灰烬未绑定& amp;属于 [英] Ember Unbound & Belongsto

查看:49
本文介绍了灰烬未绑定& amp;属于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做{{unbound title}}或

I have no problem doing {{unbound title}} or

{{#each file}}
{{unbound filename}}
{{/each}}

在模型上.

但是,余烬中的所有属于对象对我来说真的是个问题.没有任何办法可以解决

BUT, all belongsto object in ember is really problematic for me. None of ways below work

{{unbound location.address}}

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

这两个都导致空输出

推荐答案

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

At the time your model is being processed, any belongsTo relationships are not resolved yet. Since you're not binding, it can't retroactively update once that data is available either. I found this workaround yesterday, helping my solve my (similar) issues with belongsTo: https://github.com/emberjs/data/issues/1405

对于现有记录,您需要执行以下操作:您的路线:

For existing records, you need to do something like the following in your route:

// 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尝试将其放入内容时(不包含)存在:

And in your controller, be sure to declare the properties before setting them as Ember tries to throw then into content when they don't exist:

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

通过在beforeModel挂钩中返回一个Prom,您可以告诉在加载模型之前解决承诺的途径,这也意味着在进行任何渲染之前.这给您的应用程序加载时间数据先绑定到选择框.

By returning a promise in the beforeModel hook, you are telling the route to resolve the promise BEFORE loading the model, which also mean before any rendering occurs. This gives your application time to load the data up front before binding it to the select boxes.

这篇关于灰烬未绑定& amp;属于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆