【问题标题】:EmberJS - set default value of Select ViewEmberJS - 设置选择视图的默认值
【发布时间】:2014-08-17 11:19:47
【问题描述】:

我需要为表单中的选择视图设置默认值。该表单在controller 中设置了一个国家/地区列表,这用作选择的contentBinding

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

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

3 个国家/地区选项是“Asutria”、“Australia”和“Canada”。现在我想将“澳大利亚”设置为默认值。任何帮助表示赞赏。

【问题讨论】:

    标签: javascript ember.js


    【解决方案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 中进行了解释

    【讨论】:

    • 谢谢。我浏览了文档,不知道我是怎么错过的。
    • 没问题。很高兴为您提供帮助
    猜你喜欢
    • 2020-05-19
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-08
    • 1970-01-01
    相关资源
    最近更新 更多