【问题标题】:Bind Ember.select to values loaded from the server将 Ember.select 绑定到从服务器加载的值
【发布时间】:2014-02-12 21:59:40
【问题描述】:

我有一个这样的选择视图:

App.sectors = ["Alpinism", "Climbing", "Kayaking];

{{view Ember.Select contentBinding="App.sectors"}}

现在,我希望使用来自服务器的值填充选择视图,而不是固定值的向量;换句话说,我想做类似的事情:

App.sectors = function() {
    return this.store.find('sector');
}

但这不起作用,因为 Ember 说我必须将向量传递给 contentBinding 而不是函数...

(我定义了扇区模型:

App.Sector = DS.Model.extend({
    description: DS.attr('string')
});

我的安静的服务器正确回答“域/扇区”上的 EmberData 获取请求)

【问题讨论】:

    标签: ember.js ember.select


    【解决方案1】:

    在范围内的控制器上添加一个计算属性并从那里返回您的真实数据。

    App.IndexController = Em.Controller.extend({
      colors: function(){
        return this.get('store').find('color');
      }.property()
    });
    

    http://emberjs.jsbin.com/OxIDiVU/199/edit

    【讨论】:

    • 太棒了!非常感谢;)
    • 能否也告诉我如何设置 Ember Select View 的默认选中值?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-28
    相关资源
    最近更新 更多