Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有json数据的自动完成jquery ui无法正常工作小故障_Javascript_Jquery_Json_Jquery Ui - Fatal编程技术网

Javascript 带有json数据的自动完成jquery ui无法正常工作小故障

Javascript 带有json数据的自动完成jquery ui无法正常工作小故障,javascript,jquery,json,jquery-ui,Javascript,Jquery,Json,Jquery Ui,我有以下javascript代码: $("#lcountry").autocomplete({ source: function (request, response) { $.ajax({ url: "https://graph.facebook.com/search?type=adcountry&limit=3", type: "GET", data: request,

我有以下javascript代码:

$("#lcountry").autocomplete({
    source: function (request, response) {
         $.ajax({
             url: "https://graph.facebook.com/search?type=adcountry&limit=3",
             type: "GET",
             data: request,
             success: function (data) {
                 response($.map(data, function (el) {
                     return {
                         label: el.name,
                         value: el.country_code
                     };
                 }));
             }
         });
    },
    select: function (event, ui) {
        // Prevent value from being put in the input:
        this.value = ui.item.label;
        // Set the next input's value to the "value" of the item.
        $(this).next("input").value(ui.item.value);
        event.preventDefault();
    }
});
不幸的是,这不起作用。当我查看控制台时,这里是结果,显然我们可以看到国家,我希望能够在jquery autocomplete中返回名称值:

{
   "data": [
      {
         "country_code": "US",
         "name": "United States",
         "supports_region": "true",
         "supports_city": "true"
      },

      {
         "country_code": "AR",
         "name": "Argentina",
         "supports_region": "false",
         "supports_city": "true"
      },
      {
         "country_code": "AU",
         "name": "Australia",
         "supports_region": "true",
         "supports_city": "true"
      }
   ],
   "paging": {
      "next": "https://graph.facebook.com/search?type=adcountry&limit=5&term=c&offset=5"
   }
}

您需要使用
数据。数据
-
数据
是一个对象,它包含一个键
数据
,具有国家/地区列表

$("#lcountry").autocomplete({
    source: function (request, response) {
        $.ajax({
            url: "https://graph.facebook.com/search?type=adcountry&limit=3",
            type: "GET",
            data: request,
            success: function (data) {
                response($.map(data.data, function (el) {
                    return {
                        label: el.name,
                        value: el.country_code
                    };
                }));
            }
        });
    },
    select: function (event, ui) {
        // Prevent value from being put in the input:
        this.value = ui.item.label;
        // Set the next input's value to the "value" of the item.
        $(this).next("input").value(ui.item.value);
        event.preventDefault();
    }
});
演示: