【问题标题】:Bind object to Select2 option?将对象绑定到 Select2 选项?
【发布时间】:2015-11-02 01:47:03
【问题描述】:

所以我有一个 Select2 表单:

<require from="./select2"></require>
<select select2="selected-values.two-way: selectedStuff" data-placeholder="Choose Stuff" multiple>
    <option repeat.for="thing of stuff">${thing.id}</option>
</select>

我可以使用它访问selectedStuff,它是所选things 的ids 的数组。但是,我想获得things 本身的数组,而不是他们的ids。在我的用例中,从id 中查找thing 是不可行的。有什么方法可以将thing 对象绑定到&lt;option&gt; 元素,这样我就可以获得选定things 的数组,而不是选定thing.ids 的数组?

【问题讨论】:

    标签: javascript jquery-select2 aurelia jquery-select2-4


    【解决方案1】:

    &lt;option&gt; 元素的 value 属性只接受字符串。使用模型属性存储非字符串值:

    <select select2 multiple value.bind="selectedThing2">
      <option repeat.for="thing of things" model.bind="thing">${thing.name}</option>
    </select>
    

    这是一个正常工作的插件:

    http://plnkr.co/edit/mEpr8E?p=preview

    这里是选择与 aurelia 绑定的文档:http://aurelia.io/docs.html#select-elements

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-29
      • 2020-02-17
      • 1970-01-01
      • 2014-11-05
      • 2015-10-14
      • 1970-01-01
      相关资源
      最近更新 更多