0

I'm trying to update a list of models from my AppView linked to my Collection but I'm not sure how should I do it.

I thought to do it on the render function, the purpose is to set a specific property I've called treeId which is 0 by default and I would change it to a different value after the rendering to set a different treeId html attribute inside the html template for every model.

render: function() {
    console.log("View - App.render");
    this.statusOpenedFolder();
    var parentTreeId = this.parentTreeId;

    _.each(this.collection.toJSON(), function (model, index) {
        model.treeId = parentTreeId + index;
        console.log("treeId edit " + model.treeId);
    });

    var assetsChildren = _.template(this.tmplAssetsChildren, {items:this.collection.toJSON()});
    this.$currentTarget.find("ul").remove();
    this.$currentTarget.append(assetsChildren);
    this.delegateEvents();

    return;
}

Basically i'll need it to get where is the children of a tree menu.

Obviously the _.each method don't work because I'm doing it without any reference to the collection, how can I do it?

4

1 回答 1

0

你可以this.collection.models在你的_.each函数中使用,或者简单地说this.collection.each,因为它混合在Backbone.Collection. 但是,我不确定您是否要在每次渲染时重新计算它——我想this.parentTreeId不会改变,所以您可以在initialize.

于 2013-06-19T18:41:01.880 回答