gpt4 book ai didi

ember.js - Access 在 ember 中的计算属性中有很多通过 foreach

转载 作者:行者123 更新时间:2023-12-01 01:04:45 25 4
gpt4 key购买 nike

所以我有一个 hasMany 定义为
任务:DS.hasMany('quest')
我有一个属性,它应该通过每个任务并计算出总数。
函数看起来像这样,

questXP: function() {
var amount = 0;

this.get('quests').forEach(function(item)
{
console.log(item.get('xpReward'));
amount += parseInt(item.get('xpReward'));
});
return amount;
}.property('quests'),

我试过向 hasMany 添加 async: true ,但它完全停止了 forEach 的工作。目前它循环了 3 次(我有 3 个任务)但它无法访问任何任务的属性。
我的想法是这与任务仍在加载的事实有关。

关于我做错了什么的任何想法?

最佳答案

您的计算属性取决于每个 xpReward属性(property)。是否需要使用quests.@each.xpReward而不是 quests .

questXP: function() {
var amount = 0;

this.get('quests').forEach(function(item)
{
console.log(item.get('xpReward'));
amount += parseInt(item.get('xpReward'));
});
return amount;
}.property('quests.@each.xpReward'),

关于ember.js - Access 在 ember 中的计算属性中有很多通过 foreach,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19771583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com