【问题标题】:Ember Unbound & BelongstoEmber Unbound & Belongsto
【发布时间】:2014-09-22 23:32:36
【问题描述】:

我做 {{unbound title}} 或

没问题
{{#each file}}
{{unbound filename}}
{{/each}}

在模型上。

但是, 余烬中的所有属于对象对我来说确实有问题。 以下方法均无效

{{unbound location.address}}

{{with location}}
{{unbound address}}
{{/with}}

这两个结果都是空输出

【问题讨论】:

    标签: ember.js model handlebars.js


    【解决方案1】:

    在处理您的模型时,尚未解决任何 belongsTo 关系。由于您没有绑定,因此一旦该数据可用,它也无法追溯更新。我昨天找到了这个解决方法,帮助我解决了belongsTo 的(类似)问题:https://github.com/emberjs/data/issues/1405

    对于现有记录,您需要在 你的路线:

    // your-route beforeModel: function() {   var self = this;   return
    Em.RSVP.hash({
        firstBelongsTo: this.store.find('first-belongs-to'),
        secondBelongsTo: this.store.find('second-belongs-to')
        }).then(function (models) {
          self.controllerFor('this-route').setProperties(models);   });
    

    并且在你的控制器中,一定要在之前声明属性 将它们设置为 Ember 尝试将它们放入内容中 存在:

    // your-controller App.MyController = Ember.Controller.extend({  
    firstBelongsTo: null,   secondBelongsTo: null });
    

    通过在 beforeModel 钩子中返回一个承诺,你是在告诉 在加载模型之前解决承诺的路线,这也意味着 在任何渲染发生之前。这使您的应用程序有时间加载 在将数据绑定到选择框之前将其预先设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-02
      相关资源
      最近更新 更多