我正在使用Knockout JqAutocomplete插件。当我从自动填充中选择一个项目时,我想为该选择选择一个ID和一个名称。 我知道JqAutocomplete的文档似乎可以很好地解释它,但我尝试了所有的变化,但我无法使它工作,
<table>
<tr>
<th>remote data</th>
</tr>
<tr>
<td>
<input data-bind="jqAuto: { source: remoteHandler, value: remoteValue, inputProp: remoteTest, labelProp: 'test', valueProp: 'val', options: { delay: 250 } }" />
</td>
</tr>
<tr>
<td>
<pre data-bind="text: ko.toJSON(remoteValue)"></pre>
<pre data-bind="text: ko.toJSON(remoteTest)"></pre>
</td>
</tr>
</table>
var ViewModel = function() {
this.remoteValue = ko.observable();
this.remoteTest = ko.observable();
this.remoteHandler = function(term, callback) {
setTimeout(function() {
callback([
{ test: term + "-1", val: 1 },
{ test: term + "-2", val: 2 },
{ test: term + "-3", val: 3 },
{ test: term + "-4", val: 4 },
{ test: term + "-5", val: 5 }
]);
}, 500);
}
};
ko.applyBindings(new ViewModel());
请参阅http://jsfiddle.net/arame3333/b0jqmmjt/1/
和https://github.com/rniemeyer/knockout-jqAutocomplete
我只想显示文字而不是Id。但是在底层的viewmodel中我想要更新它们。
答案 0 :(得分:0)