Ember数据具有许多异步观察属性“简单”问题 [英] Ember Data hasMany async observed property "simple" issue

查看:102
本文介绍了Ember数据具有许多异步观察属性“简单”问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的Ember应用程序(Ember 1.5.1)有两个型号(Ember Data beta7):项目和标签。项目有很多标签。



我也有一个没有更新的标签的计算属性。计算的属性是一个简单的检查,以查看是否有任何标签(即不为空)。我尝试过各种各样的事情。我得到了arrayComputed,然后停止。检查异步相关模型的计数是否高于0应该是微不足道的!我已经尝试过标签。,标签,每个,标签。@ each.status,tags。@ each.isLoaded,tags.length等各种其他的东西。

belongsTo的计算属性正常。

  App.Item = DS。 Model.extend({
tags:DS.hasMany(tag,inverse:item,async:true),
hasTags:function(){
return!Em.isEmpty this.get(tags));
} .property(tags)
});

App.Tag = DS.Model.extend(
item:DS.belongsTo(item,inverse:tags),
hasItem:function(){
return!Em.isEmpty(this.get('))
} .property(item)
);

如果我将其更改为这样读取,那么日志会在其中打印一行,因此承诺实际上是满载和装载。我只是不知道在计算的财产上放置什么,以便在承诺履行时重新加载。我觉得我缺少超级明显的东西:

  App.Item = DS.Model.extend({
标签:DS.hasMany(tag,inverse:item,async:true),
hasTags:function(){
this.get(tags)然后(function(tags) {
console.log(如果打印标签是loding);
});
return!Em.isEmpty(this.get(tags));
} .property(tags)
});

2014年5月7日



好的,所以我没有完全解释这个问题,第一次,我猜,因为我没有完全明白是什么错误...我继续在以下堆栈溢出问题的疑问:使用Ember DataRoute的模型钩子过滤器不加载依赖的计算属性

解决方案

我相信你在找什么是这样的:

  App.Item = DS.Model.extend({
标签:DS.hasMany(tag,inverse:item,async :true),
hasTags:function(){
this.get(tags)。then(function(tags){
console.log(打印);
});
return!Em.isEmpty(this.get(tags));
} .property(tags。@ each)
});

由于标签是一个数组,您希望在添加或删除标签时收到通知。 '。@ each'将会在这种情况下更新。


Hopefully you can help me!

My Ember App (Ember 1.5.1) has two models (Ember Data beta7): Item and Tag. Item hasMany Tags.

I also have a computed property on tags which doesn't update. The computed property is a simple check to see if there are any tags (ie not empty). I've tried various things. I got as far as arrayComputed and then stopped. It should be reasonably trivial to check if an async related model has a count higher than 0! I've tried "tags.[]", "tags.@each", "tags.@each.status", "tags.@each.isLoaded", "tags.length" and various other things.

The computed property on the belongsTo works fine.

App.Item = DS.Model.extend({
  tags: DS.hasMany("tag", inverse: "item", async: true),
  hasTags: function() {
    return !Em.isEmpty(this.get("tags"));
  }.property("tags")
});

App.Tag = DS.Model.extend(
  item: DS.belongsTo("item", inverse: "tags"),
  hasItem: function() {
    return !Em.isEmpty(this.get('))
  }.property("item")
);

If I change it to read like this, then the log gets a line printed in it, so the promise is actually fulfilling and loading. I just don't know what to put on the computed property to make it reload when the promise has fulfilled. I feel like I'm missing something super obvious:

App.Item = DS.Model.extend({
  tags: DS.hasMany("tag", inverse: "item", async: true),
  hasTags: function() {
    this.get("tags").then(function(tags) {
      console.log("The tags are loding if this is printed");
    });
    return !Em.isEmpty(this.get("tags"));
  }.property("tags")
});

[ edit ] 7 May 2014

Okay so I didn't fully explain the question properly the first go around I guess because I didn't fully understand what was wrong... I've continued the quesiton in the following stack overflow issue: Route's Model Hook with Ember Data "filter" not loading dependent computed property

解决方案

I believe what you are looking for is this:

App.Item = DS.Model.extend({
  tags: DS.hasMany("tag", inverse: "item", async: true),
  hasTags: function() {
    this.get("tags").then(function(tags) {
      console.log("The tags are loding if this is printed");
    });
    return !Em.isEmpty(this.get("tags"));
  }.property("tags.@each")
});

Because tags is an array, you want to be notified when tags are added or removed. the '.@each' will make it update when this happens.

这篇关于Ember数据具有许多异步观察属性“简单”问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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