1

嗨,我正在尝试将 Select2(多选)与 Durandal(http://jsfiddle.net/anasnakawa/6XvqX/381/)一起使用,但下面的弹出窗口不起作用是我的 VM 和 HTML 的一部分,我正在尝试绑定输入的状态列表它应该作为自动完成工作,但似乎有一个问题显示选择弹出窗口,有人可以帮忙吗

define(['durandal/app', 'services/datacontext', 'plugins/router', 'services/bindinghandlers'],
function (app, datacontext, router) {
    var withs = ko.observableArray(),
        states = [
    { id: "AL", text: "Alabama" },
    { id: "AK", text: "Alaska" },
    { id: "AZ", text: "Arizona" },
    { id: "AR", text: "Arkansas" },
    { id: "CA", text: "California" },
    { id: "CO", text: "Colorado" },
    { id: "CT", text: "Connecticut" },
    { id: "DE", text: "Delaware" },
    { id: "FL", text: "Florida" },
    { id: "GA", text: "Georgia" },
    { id: "HI", text: "Hawaii" },
    { id: "ID", text: "Idaho" },
    { id: "IL", text: "Illinois" },
    { id: "IN", text: "Indiana" },
    { id: "IA", text: "Iowa" },
    { id: "KS", text: "Kansas" },
    { id: "KY", text: "Kentucky" },
    { id: "LA", text: "Louisiana" },
    { id: "ME", text: "Maine" },
    { id: "MD", text: "Maryland" },
    { id: "MA", text: "Massachusetts" },
    { id: "MI", text: "Michigan" },
    { id: "MN", text: "Minnesota" },
    { id: "MS", text: "Mississippi" },
    { id: "MO", text: "Missouri" },
    { id: "MT", text: "Montana" },
    { id: "NE", text: "Nebraska" },
    { id: "NV", text: "Nevada" },
    { id: "NH", text: "New Hampshire" },
    { id: "NJ", text: "New Jersey" },
    { id: "NM", text: "New Mexico" },
    { id: "NY", text: "New York" },
    { id: "NC", text: "North Carolina" },
    { id: "ND", text: "North Dakota" },
    { id: "OH", text: "Ohio" },
    { id: "OK", text: "Oklahoma" },
    { id: "OR", text: "Oregon" },
    { id: "PA", text: "Pennsylvania" },
    { id: "RI", text: "Rhode Island" },
    { id: "SC", text: "South Carolina" },
    { id: "SD", text: "South Dakota" },
    { id: "TN", text: "Tennessee" },
    { id: "TX", text: "Texas" },
    { id: "UT", text: "Utah" },
    { id: "VT", text: "Vermont" },
    { id: "VA", text: "Virginia" },
    { id: "WA", text: "Washington" },
    { id: "WV", text: "West Virginia" },
    { id: "WI", text: "Wisconsin" },
    { id: "WY", text: "Wyoming" }
        ];
    var vm = {         

        withs: withs,            
        states: states,

    };

    return vm;
});

<select multiple="true" data-bind="options: states, optionsValue: 'id', optionsText: 'text', selectedOptions: withs, select2: {}" style="width: 300px"></select>
4

1 回答 1

0
  1. select2在 main.js 内的 Require.js 配置中注册:

    requirejs.config({
      paths: {
        'select2': 'path/to/select2'
      }
    });
    
  2. 在您的视图模型中定义它:

    define(['select2'], function (select2) {
      // ...
    });
    
  3. 不要忘记声明它。您必须使用attached回调:

    var vm = {
      withs: withs,
      states: states,
      attached: function() {
        $('select').select2();
      }
    };
    
于 2013-10-11T13:55:17.587 回答