我的代码如下:
var AppRouter = Backbone.Router.extend({
_data: null,
_length: 0,
_index: null,
_todos: null,
_subtodolist: null,
_subtodos: null,
routes: {
"*action": "index",
"category/:name": "hashcategory"
},
initialize: function(options){
var self = this;
if (this._index === null){
$.ajax({
url: 'data/todolist.json',
dataType: 'json',
data: {},
success: function(data) {
self._data = data;
self._todos = new TodosCollection(data);
self._index = new CategoriesView({collection: self._todos});
//self._index.render();
}
});
return this;
}
return this;
},
index: function(){
this._index.render();
},
....
Run Code Online (Sandbox Code Playgroud)
但是当我开始使用时,firebug控制台面板总是告诉我函数中this._index是null index.我必须self._index.render()在$.ajax success回调函数的底部使用以进行主页渲染(上面已注释掉).似乎 …