骨幹Marionette.CollectionView它調用MyApp.addInitiliazer方法時從服務器呈現數據,但在Marionette.AppRouter中調用時不呈現(不顯示在html上)爲什麼它不是渲染我是cofused它是一個錯誤?Backbone Marionette收集視圖路徑更改渲染與數據視圖不起作用
更新: 當我導航到/ app#other時,回到/ app#samples collection view不顯示數據。如果你更好的apporache這個應用程序,請告訴我,我很高興。
App.js
var MyApp = new Backbone.Marionette.Application();
MyApp.addRegions({
// Layout regions
menu: '#menu',
headermenu: '.top-menu',
content: '#views',
// Sub pages
innermenu: '#innermenu',
samples: '#sample-container'
});
MyApp.vent.on("routing:started", function() {
if (!Backbone.History.started) {
Backbone.history.start({ appRoot: '/app#' });
}
});
SampleAppList.js
MyApp.SampleApp.SampleList = {};
MyApp.SampleApp.SampleList.Sample = Backbone.Model.extend({
id: null,
name: '',
picture: '/assets/img/default-sample.jpg'
});
MyApp.SampleApp.SampleList.SampleCollection = Backbone.Collection.extend({
model: MyApp.SampleApp.SampleList.Sample,
url: '/api/samples'
});
MyApp.SampleApp.SampleList.SampleItemView = Backbone.Marionette.ItemView.extend({
template: "#sample-view",
tagName: 'li'
});
MyApp.SampleApp.SampleList.SampleCollectionView = Backbone.Marionette.CollectionView.extend({
itemView: MyApp.SampleApp.SampleList.SampleItemView,
tagName: 'ul',
className: 'sample-list',
});
SampleApp.js
MyApp.SampleApp = {};
MyApp.SampleApp.IndexView = Backbone.Marionette.ItemView.extend({
template: '#sample-layout'
});
MyApp.SampleApp.IndexInnerMenuView = Backbone.Marionette.ItemView.extend({
template: '#sample-view-inner-menu',
});
MyApp.SampleApp.Router = Backbone.Marionette.AppRouter.extend({
appRoutes: {
"samples": "LoadPage"
}
});
MyApp.SampleApp.LoadPage = function() {
//utils.setDocumentTitle('samples');
var index = new MyApp.SampleApp.IndexView();
MyApp.content.show(index);
var inner = new MyApp.SampleApp.IndexInnerMenuView();
MyApp.innermenu.show(inner);
var sCollection = new MyApp.SampleApp.SampleList.SampleCollection();
sCollection.fetch();
var cv = new MyApp.SampleApp.SampleList.SampleCollectionView({ collection: sCollection });
MyApp.samples.show(cv);
console.log('Route: Samples');
};
MyApp.addInitializer(function() {
var router = new MyApp.SampleApp.Router({
controller: MyApp.SampleApp
});
MyApp.SampleApp.LoadPage();
MyApp.vent.trigger("routing:started");
});
OtherApp.js
MyApp.OtherApp = {};
MyApp.OtherApp.IndexView = Backbone.Marionette.ItemView.extend({
template: '#other-layout'
});
MyApp.OtherApp.IndexInnerMenuView = Backbone.Marionette.ItemView.extend({
template: '#other-view-inner-menu',
});
MyApp.OtherApp.Router = Backbone.Marionette.AppRouter.extend({
appRoutes: {
"other": "LoadOtherPage"
}
});
MyApp.OtherApp.LoadOtherPage = function() {
var index = new MyApp.OtherApp.IndexView();
MyApp.content.show(index);
var innermenu = new MyApp.OtherApp.IndexInnerMenuView();
MyApp.innermenu.show(innermenu);
};
MyApp.addInitializer(function() {
MyApp.OtherApp.Router = new MyApp.OtherApp.Router({
controller: MyApp.OtherApp
});
MyApp.vent.trigger("routing:started");
});
我tryed給出相同的結果「變種路由器」。我用我的所有代碼更新我的帖子。 – c3h4n 2015-02-07 15:39:17
我更新了我的問題,請你可以看看 – c3h4n 2015-02-07 16:23:11
我認爲你讓課程與對象混淆。閱讀文檔:http://marionettejs.com/docs/v2.3.2/marionette.controller.html – 2015-02-07 19:57:38