2
モデル内でコレクションをネストしようとしました。 私はレシピを手に入れました。レシピには成分(モデル)を持つingredientslist(コレクション)があります。backbone.jsネストされたコレクションでイベントの発生を追加しますが、親モデルを返します
は、私が最初のバックボーンのリレーショナル・モデルを試してみましたが、その後、私はコレクションに成分を追加すると、ここでbackbone.js structuring nested views and models
提供方法を選んだ、追加イベントがトリガされます。
initialize: function(){ recipe = this.model; console.log(recipe); _.bindAll(this,"add","remove"); recipe.ingredientlist.each(this.add); recipe.ingredientlist.bind('add', this.add); recipe.ingredientlist.bind('remove', this.remove); this.render(); }, add: function(ingredient){ console.log(ingredient); }
私のコンソールには、追加された成分を出力しようとしていますが、レシピモデルが返されています。
私のモデルは、この
MyApp.Models.Recipe = Backbone.Model.extend({ initialize: function(){ this.ingredientlist = new MyApp.Collections.IngredientList(); this.ingredientlist.parent = this; });
どのように見えるか、私はちょうどコレクション、全体ではなくレシピモデルに追加された成分を返すようにバインドを得るのですか?
私の悪い、すべての時間を無駄にして申し訳ありません、私は私の最後に何かを誤解しました。 – pedalpete