gpt4 book ai didi

javascript - 主干听嵌套模型/集合?

转载 作者:行者123 更新时间:2023-11-30 10:16:17 25 4
gpt4 key购买 nike

所以下面只是我在做什么的粗略想法,集合是嵌套的,我需要在 this.collection.get('players')< 时调用 getMax()/ 更改

module.exports = LeadersCollectionView = Marionette.CompositeView.extend({
className: 'live-stats',
template: require('../../../templates/leaders/live-stats.hbs'),
initialize: function() {
this.listenTo(this.collection, 'change', this.render);
//this.listenTo(this.collection.get('players'), 'change', this.render);
},
getMax : function(attribute) {
console.log('getMax called')
var home = this.collection.get('5368dcc1227a937829b2cb4a').players.models;
var away = this.collection.get('5368dcd9227a937829b2cb4c').players.models;
leaders = new PlayersCollection(home.concat(away))
return leaders.max(function(leader) {
return leader.get(attribute);
});
},
templateHelpers:function(){
return {
maxPoints: this.getMax('points').get('player_name')
}
},
itemView: leadersView,
appendHtml: function(collectionView, itemView){
collectionView.$('.live-data .created-teams').append(itemView.el);
}
});

我之前使用的是 backbone-relational,然后决定放弃它,现在我想我可能又需要它了,但希望有更简单的方法。

因此,虽然可能有更好的方法来编写 getMax() 函数(显然静态团队目前已通过),但如果我无法更新 ,我将无法真正使用它getMax() 当玩家模型中的点发生变化时。

所以我的问题是我可以在没有 Backbone 关系的情况下听取嵌套模型的变化吗?我该怎么做?

最佳答案

看看Backbone.DeepModel : 你可以订阅 change:players.* 事件

或者坚持 Backbone 关系。

关于javascript - 主干听嵌套模型/集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23520380/

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