我尝试通过asmx网络服务为自动填充字段设置键/值列表。
这是我返回jquery的数据:
> { "419": "Alexander High School", "370": "Alfred I. duPont Middle
> School", "245": "Allatoona High School", "120": "Allen D. Nease
> High School", "365": "Alpharetta High School", "232": "Andrew
> Jackson High School", "371": "Apalachee High School" }
我创建数据的方式是:
[WebMethod(true)]
public string GetSchoolList()
{
var schItem = new Dictionary<string, string>();
var schools = UndercBLL.GetSchools().ToList();
foreach (SchoolItem school in schools)
{
schItem.Add(school.Id.ToString(), school.Name);
}
var json = JsonConvert.SerializeObject(schItem, Formatting.Indented);
return json;
}
jquery部分设置如下:
$("#tags").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
url: "SchoolInfo.asmx/GetSchoolList",
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (data) {
alert(data);
response($.map(data, function (value, key) {
return {
label: value,
value: key
};
}));
}
});
},
minLength: 2
});
知道我做错了什么吗?我在萤火虫中没有收到任何错误,但正如您所看到的,我没有显示任何自动填充选项。