嗨同行程序員,使用WCF服務顯示帶有jQuery自動完成功能的數據?
我有一個數據庫的一些數據。我創建了一個使用jQuery Autocomplete從數據庫獲取所有名稱的WCF服務。我使用JSON獲得響應,但是我想在自動完成中顯示它。
這是我的jQuery的樣子:
$(function() {
function log(message) {
$("<div>").text(message).prependTo("#log");
$("#log").scrollTop(0);
}
$("#city").autocomplete({
source: function (request, response) {
$.ajax({
url: "/service.svc/GetData",
dataType: "jsonp",
data: {
DataName: request.term
},
success: function (data) {
response(data);
}
});
},
minLength: 3,
select: function (event, ui) {
log(ui.item ?
"Selected: " + ui.item.label :
"Nothing selected, input was " + this.value);
},
open: function() {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function() {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
});
我是相當新的WCF和想知道下一步是什麼?我如何映射數據以便顯示它?
JSON數據輸出看起來像這樣:
{"GetDataResult":[{"Name":"Fran $","CategoryId":102,"dataId":1,"IndexId":16,"InsertedDate":null,"Manual":false}
「GetData」服務的JSON看起來像什麼?自動完成期望它處於某種格式 – 2015-02-09 15:35:12
我編輯了第一篇文章。 – user3410846 2015-02-09 15:38:56
所以,爲了清楚起見,是否要顯示陣列中每個結果的'Name'作爲建議? – 2015-02-09 15:40:04