Backbone.on('documentEdit', this.onDocumentEdit, this);
Backbone.trigger('documentEdit');
2.regionvar region = new Backbone.Marionette.Region({
el: "#container"
});
--它会控制#container里面的DOMApp.addRegions({
container: "#container",
footer: "#footer"
});
--全局添加regionscompositeview继承自collectionview,collectionview只能迭代集合。
但是compositeview可以递归迭代集合的集合。
4.router
etc. http://baidu.com/#test------->test 就是hash
4.2-为什么要用hash?
因为hash服务端是获取不到的,并且hash不会改变浏览器页面。但是借助于前端js脚本,可以做到有效区分当前页面。所以,可以利用hash来做到前端分离。
4.3-如何监听hashchange?
Talent.$(window).on('hashchange',function(){
console.log(1);
});
4.4-talent怎么做的?
// Depending on whether we're using pushState or hashes, and whether
// 'onhashchange' is supported, determine how we check the URL state.
if (this._hasPushState) {
Backbone.$(window).on('popstate', this.checkUrl);
} else if (this._wantsHashChange && ('onhashchange' in window) && !oldIE) {
Backbone.$(window).on('hashchange', this.checkUrl);
} else if (this._wantsHashChange) {
this._checkUrlInterval = setInterval(this.checkUrl, this.interval);
}
4.5-router和这个有啥关系?
路由:路由(routing)是指分组从源到目的地时,决定端到端路径的网络范围的进程;var TodoView = Backbone.View.extend({
initialize: function(){
_.bindAll(this, 'render', 'remove');
this.model.bind('change', 'this.render');
this.model.bind('delete', 'this.remove');
},
remove: function(){
$(this.el).remove();
}
});
--marrionetee更简单了,close方法close: function(){
this.stopListening();
this.triggerMethod("close");
this.unbind();
}
它也会清理所有的Marionette的view默认设置的配置view.listenTo(model, 'change', view.render);
view 监听 model 的 change 事件,然后触发 view.renderBackbone.Marionette.View.extend({ // We don't normally directly extend this view
modelEvents: {
'change:attribute': 'attributeChanged render',
'destroy': 'modelDestroyed'
},
render: function(){ … },
attributeChanged: function(){ … },
modelDestroyed: function(){ … }
});