Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

javascript - select2我不想从json中获取数据(select2 I don't want to get data out of json)

My script won't load any data in the Select2.

(我的脚本不会在Select2中加载任何数据。)

I made data from laravel controller with response JSON data, this result json

(我从laravel控制器使用响应JSON数据制作了数据,此结果为json)



  "results": [
    {
      "id": 1,
      "code": "11",
      "name": "jackson",
    },
    {
      "id": 2,
      "code": "12",
      "name": "michael,

    },

this my script code

(这是我的脚本代码)

$('.name_user').select2({
      width: "100%",
      placeholder: "Search...",
        ajax: {
          url: "{{route('name_user')}}",
          processResults: function(data) {
            return {
              results: $.map(data, function(obj) {
                return {
                  id: obj.id,
                  name: obj.name
                };
              })
            };
          },
          cache: true
        }

      });

How do I get data from route name_user?

(如何从路由name_user获取数据?)

  ask by misry translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...