我收到了一個帶有MarionetteJS的CompositeView加載元信息的意外行爲。從服務器端的JSON的樣子:爲什麼在此MarionetteJS複合視圖中未顯示元信息?
{ "meta": { "total": 2 }, "movies": [ { "category": "Action", "description": "Another story goes ....", "id": 1, "stars": "4.0", "title": "My test movie" }, { "category": "Action", "description": "the story goes....", "id": 2, "stars": null, "title": "my second movie" } ] }
我用一個骨幹集合設置像元信息:
MA.Collections.Movies = Backbone.Collection.extend({ url: '/api/movies.json', parse: function(data) { this.meta = new MA.Models.MetaMovie(data.meta); return data.movies; } }); MA.addInitializer(function() { MA.Collections.Movies.model = MA.Models.Movie; })
但是,當我嘗試從CompositeView中訪問此元變量,收集被正確初始化,而元信息似乎丟失了。任何想法如何將這個元信息提供給CompositeView的模型?
PS控制檯輸出看起來像:
你只在你的分析函數中返回data.movies。 – steveax 2013-04-21 22:42:43
正確。我正在嘗試在這裏建議的方法:http://stackoverflow.com/questions/5711245/backbone-js-getting-extra-data-along-with-the-request – poseid 2013-04-22 06:10:53
如果您發佈的路由器/控制器的代碼創建您的收藏和查看實例我將向您展示完成您正在嘗試執行的操作的明確方法。 – 2013-04-22 15:50:50