Ember Unbound&属于 [英] Ember Unbound & Belongsto

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

问题描述

我没有问题{{unbound title}}或

  {{每个文件}} 
{{unbound filename}}
{{/ each}}

/ p>

BUT,
所有属于ember的对象对我来说真的有问题。
以下工作方式

  {{unbound location.address}} 

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

这两个都导致空输出

解决方案

当您的模型处理时,任何 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 to)',
secondBelongsTo:this.store.find('second-belongs-到$)
})然后(function(models){
self.controllerFor('this-route')。setProperties(models);});




在控制器中,请确保在$ b之前声明属性$ b设置它们,因为Ember尝试将它们抛出到内容中,当它们不存在
时:




 code> //你的控制器App.MyController = Ember.Controller.extend({
firstBelongsTo:null,secondBelongsTo:null});




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



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

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

on a model.

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

{{unbound location.address}}

and

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

both of these two result in empty output

解决方案

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);   });

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 });

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.

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

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