如何使用durandal JS創建自動完成文本框。鑑於代碼不起作用。使用Durandal JS的自動完成文本框
視圖模型(JS)
define(['repositories/customerRepository', 'plugins/router', 'plugins/http', 'durandal/app', 'knockout'], function (customerRepository, router, http, app, ko)
{
return {
router: router,
activate: function() {
var data = customerRepository.listMovies();
$(function() {
$("#movie").autocomplete({
source: data,
focus: function (event, ui) {
$("#movie").val(ui.item.name);
return false;
},
select: function (event, ui) {
$("#movie").val(ui.item.name);
// $("#friend-id").val(ui.item.id);
return false;
}
})
.data("ui-autocomplete")._renderItem = function (ul, item) {
return $("<li>")
.append(
"<a>" + "<table><tr><td rowspan=2>" + item.name + "</td></tr><tr><td>" + item.barcode + "</td></tr></table>")
.appendTo(ul);
};
});
},
};
});
視圖(HTML)
<input id="movie" type="search" class="form-control" data-bind="value: searchModel.searchTerm" placeholder="Name/Bar code">
究竟是「不工作」?你看到什麼症狀? – RockResolve