相关疑难解决方法(0)

Backbone.js路由器初始化不会立即运行

我的代码如下:

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回调函数的底部使用以进行主页渲染(上面已注释掉).似乎 …

backbone.js backbone-routing

3
推荐指数
1
解决办法
7029
查看次数

标签 统计

backbone-routing ×1

backbone.js ×1