我需要为表单中的选择视图设置默认值。该表单具有在controller
中设置的国家/地区列表,该列表用作Select的contentBinding
。
但是,此选择的实际值来自路由的model
。因此,我必须使用控制器中其他属性的值填充“选择”,然后将当前模型设置为默认值。
http://emberjs.jsbin.com/darus/2/
这3个国家/地区选项分别是“奥祖”,“澳大利亚”和“加拿大”。现在,我想将“ Australia”设置为默认值。任何帮助表示赞赏。
最佳答案
{{view Ember.Select
class="contactCountry"
contentBinding="countryOptions"
optionLabelPath="content.name"
optionValuePath="content.id"
selectionBinding="address.id"
value = selectedCountry.id
}}
App.IndexController = Ember.ObjectController.extend({
countryOptions : [
{id: 1, name:"Austria"},
{id: 2, name: "Australia"},
{id: 3, name: "Canada"}
],
selectedCountry : {
id: 2
}
});
这一切都在docs中进行了解释
关于javascript - EmberJS-设置选择 View 的默认值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25348731/