我需要顯示three different views
這些與three different model
或集合相關。
爲了執行這個任務我寫了下面的代碼。 (*)
請告訴我,如果這是正確的做法,無論如何它的工作原理。Backbone.View:刪除與不同型號相關的不同視圖
這裏我的問題。
在這種觀點之一中,我們假設firstView
有可能對服務器執行DELETE request
,該服務器會注意刪除與此three view
相關的所有數據。
現在我需要刪除我的三個視圖... 但從firstView
我無法訪問其他兩個視圖。
1)我該如何執行此任務?
2)我應該重新設計/改進我的實施嗎?
(*)
// module for display three different views
define([
"js/views/01View",
"js/views/02View",
"js/views/03View"
], function (FirstView, SecondView, ThirdView) {
var MainView = Backbone.View.extend({
initialize: function()
{
this.render();
},
render: function()
{
var movie_id = this.options.movie_id;
this.firstView = new FirstView(movie_id);
this.secondView = new SecondView(movie_id);
this.thirdView = new ThirdView(movie_id);
}
});
return MainView;
});
PS:
的_id用於建立集合或模型
url1: http://localhost/movie/movie_id (model1)
url2: http://localhost/movie/movie_id/followers (collection2)
ulrs: http://localhost/movie/movie_id/feeds (collection3)
當我刪除的URL參數model1與coll有關的view2和view3 ection2和collection3應該被刪除。
我對您的評論困惑,你說,你有三種不同的觀點和三個不同的模型,但你傳遞相同的model_id到你的意見。 –
model_id(同一個id)用於對服務器執行三種不同的提取,這對應於三種不同的數據模型。我將在我的問題上添加更多信息。 – underscore666
感覺就像是在圍繞視圖構建數據而不是對數據的看法。看看下面的Backbone插件:https://github.com/PaulUithol/Backbone-relational/,並正確地建立你的數據之間的關係。 –