EmberJS - 设置选择视图的默认值

时间:2014-08-17 11:19:47

标签: javascript ember.js

我需要为表单中的选择视图设置默认值。该表单包含controller中设置的国家/地区列表,用作Select的contentBinding

但是,此选择的实际值来自路线model。因此,我必须使用控制器中不同属性的值填充Select,然后将当前模型设置为默认值。

http://emberjs.jsbin.com/darus/2/

3个国家的选择是" Asutria","澳大利亚"和#34;加拿大"。现在我想设置"澳大利亚"作为默认值。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

{{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

中解释