0

我的下拉菜单正在使用以下代码生成

{{view Ember.Select contentBinding="controller.softwares" valueBinding="ss.value" optionLabelPath="content.name" optionValuePath="content.id" prompt="Select Software" name="software" }}               

目前它正在生成类似的东西

<select name="software">
......
</select>

我希望它是

<select name="software" data-id="45">
......
</select>

我试过

{{view Ember.Select contentBinding="controller.softwares" valueBinding="ss.value" optionLabelPath="content.name" optionValuePath="content.id" prompt="Select Software" name="software" data-id="ss.id" }}               

但它没有用。

4

1 回答 1

2

你必须告诉 Ember 绑定这个属性:

App.YourSelect = Ember.Select.extend({
  attributeBindings : ["data-id"]
});

{{view App.YourSelect contentBinding=controller.softwares valueBinding=ss.value optionLabelPath="content.name" optionValuePath="content.id" prompt="Select Software" name="software" data-id=ss.id }} 

这告诉 ember 将此属性添加到底层 DOM 元素。请注意我对“删除”的轻微更正。Ember 团队建议在访问对象时不要使用引号。这应该更容易将其与“选择软件”等字符串区分开来。

PS:没有测试过。可能有小错误:-)

于 2013-09-05T12:23:19.087 回答