<select data-bind="select2: {}"></select>
<input data-bind="select2: {}">
如果我使用HTML INPUT 与select2并在 foreach 与asp.net mvc绑定中进行淘汰,我会在互联网浏览器中收到此错误
Unhandled exception at line 2890, column 21 in http://localhost:4052/Scripts/knockout-3.2.0.debug.js
0x800a139e - JavaScript runtime error: query function not defined for Select2 undefined
我在mozilla和chrome中没有出现任何错误,但是当我这样做时,它们也没有像预期的那样表现
<input data-bind="select2: {allowClear: true,placeholder: ' write tags here...', multiple: true, tokenSeparators: [',']}">
当我使用<select data-bind="select2: {}"></select>
时,即使在IE中也没有错误...
基本上,我想在淘汰赛自动生成的表中有一个标签输入,可以像这样进行标记......
$("#tags1,#tags2").select2({
allowClear: true,
placeholder: "Write Tags Here...",
//createSearchChoice:function(term, data) {return {id:term, text:term};},
//createSearchChoice:function(term, data) { if ($(data).filter(function() { return this.text.localeCompare(term)===0; }).length===0) {return {id:term, text:term};} },
multiple: true,
tags: [],
tokenSeparators: [","]
//maximumInputLength: 15,
//maximumSelectionSize: 5
//data: [{id: 0, text: 'story', locked: true},{id: 1, text: 'bug'},{id: 2, text: 'task'}]
});
我使用过这个自定义绑定... https://github.com/select2/select2/wiki/Knockout.js-Integration
答案 0 :(得分:0)
编写自定义处理程序/自定义绑定的方式是错误的,
而不是$("#tags1,#tags2").select2({})
它应该是
ko.bindingHandlers.select2 = {}