我正在使用带有 jquery 自动完成功能的 knockoutjs,它工作正常,除了自动完成结果显示符号和文本。
ko.bindingHandlers.ko_mission_autocomplete = {
init: function (element, params) {
var options = params().split(' ');
var searchType = options[0];
$(element).bind("focus", function () {
$(element).change();
});
$(element).autocomplete({
source: function (request, response) {
var keyword = request.term;
//return result;
$.ajax({
type: "POST",
url: SolrUrl,
dataType: "json",
contentType: "application/json; charset=utf-8",
data: '{ "searchSource":' + searchSource + ', "searchTarget": "' + searchTarget + '", "keyword": "' + keyword + '" }',
success: function (data) {
//alert("ajax request called successfully");
var tempData = $.parseJSON(data.d);
response($.map(tempData, function (item) {
return {
label: item.Name,
value: item.Name,
id: item.ID
}
}));
},
error: function (xhr, errorType, exception) { //Triggered if an error communicating with server
var errorMessage = exception || xhr.statusText; //If exception null, then default to xhr.statusText
alert("There was an error : " + errorMessage);
},
complete: function (data) {
}
});
},
minLength: 3,
select: function (event, ui) {
$(this).change();
$(element).data("valueID", ui.item.id);
}
});
},
update: function (element, params) {
$(element).change();
}
};
当我验证 json 数据时它是正确的,但是它显示为符号。
请帮忙。
谢谢