Ember.select选择的值

时间:2014-07-21 16:39:21

标签: ember.js ember-cli

我正在使用ember-cli并想要选择绑定值

  {{view Ember.Select
      content=industries
      value=industryId         
      optionValuePath="content.id"
      optionLabelPath="content.name"}}

在路线内部我实施产业

   var industries= [];
    Ember.$.getJSON('/api/v1/Industry',function(items){
        items.forEach(function(item) {
            industries.pushObject({id:item.id,name:item.name});
        });            
    }); 
    controller.set('industries',  industries); 

我有动态模型,从服务器返回,属性'industryId'返回2,但总是有选择的元素id = 1

更新

  {{view Ember.Select
      content=industries   
      value=2   
      optionValuePath="content.id"
      optionLabelPath="content.name"
       }}

但仍未选中

2 个答案:

答案 0 :(得分:1)

如果您想设置默认值"请选择"选项,添加"提示"属性:

{{view Ember.Select
      content=industries
      value=industryId         
      optionValuePath="content.id"
      optionLabelPath="content.name"
      prompt="Please Select One"}}

答案 1 :(得分:0)

如果视图中存在属性industryId,则必须使用 view.industryId 而不是 industryId 。 如果它已经存在于控制器中并且您仍然无法获得它,那么您使用 valueBinding =" industryId" 而不是 value = industryId

相关问题