jquery自动完成远程json

时间:2014-09-10 17:46:20

标签: jquery ajax json

我在这里关注样本:

http://demos.jquerymobile.com/1.4.0/listview-autocomplete-remote/#&ui-state=dialog&ui-state=dialog

我想知道如何调整以下部分:

   .then(function (response) {
                    $.each(response, function (i, val) {
                        html += "<li>" + val + "</li>";
                    });
                    $ul.html(html);
                    $ul.listview("refresh");
                    $ul.trigger("updatelayout");
                });

我的JSON响应采用以下格式:

 {"directory": [
 {
 "firstname":"JOHN",
 "lastname":"DOE",
  "email":"user@domain.com",
  "ext":"1234",
   "dept":"ACME INC."
     }
   ]}

如何访问 .then 函数中的json数据?

干杯, 大卫

1 个答案:

答案 0 :(得分:0)

var response ={"directory": [
 {
 "firstname":"JOHN",
 "lastname":"DOE",
  "email":"user@domain.com",
  "ext":"1234",
   "dept":"ACME INC."
     }
   ]
              };

$.each(response.directory, function (i, val) {

    $.each(val, function (index, data) {

var         html = html+ "<li>" + data+ "</li>";
        alert(data);
    });
});