【问题标题】:JavaScript runtime error: query function not defined for Select2 undefinedJavaScript 运行时错误:未定义 Select2 的查询函数未定义
【发布时间】:2015-02-12 17:12:27
【问题描述】:
<select data-bind="select2: {}"></select>
<input data-bind="select2: {}">

如果我使用带有 select2 的 HTML INPUTforeach 与 asp.net mvc 绑定中的敲除,我会在 internet exploler 中收到此错误

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: [',']}">

当我使用&lt;select data-bind="select2: {}"&gt;&lt;/select&gt; 时,即使在 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

【问题讨论】:

    标签: jquery html asp.net-mvc knockout.js jquery-select2


    【解决方案1】:

    您编写自定义处理程序/自定义绑定的方式是错误的, 而不是$("#tags1,#tags2").select2({}) 应该是

    ko.bindingHandlers.select2 = {}
    

    【讨论】:

      猜你喜欢
      • 2013-01-07
      • 2015-07-06
      • 2016-06-15
      • 2013-07-12
      • 2013-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多