在我的应用程序的初始化功能期间,我想默认为我的搜索页面并将我的 LeagueCollection 作为模型传递。
我遇到了一个问题,我可以在我的应用程序初始化中向 this.searchResults 添加手表并按预期查看模型:数组 [3],但是当调用视图中的 this.model.toJSON() 时,我得到了错误对象没有方法 toJSON。
这段代码在内存集合中运行良好,然后我切换到使用backbone.localstorage.js 在本地存储应用程序数据。
所以我的问题是:为什么视图中没有填充模型?
在我的 main.js 我有
var AppRouter = Backbone.Router.extend({
    routes: {
        "": "list",
    ...
    },
    initialize: function () {
        this.searchResults = new LeagueCollection();
        this.searchPage = new SearchPage({
            model: this.searchResults.fetch()
        });
        this.searchPage.render();
    },
    ...
});
在我的搜索页面视图中
window.SearchPage = Backbone.View.extend({
    initialize:function () {
        this.template = _.template(tpl.get('search-page'));
    },
    render:function (eventName) {
        var self = this;
        $(this.el).html(this.template(this.model.toJSON()));
        this.listView = new LeagueListView({el: $('ul', this.el), model: this.model});
        this.listView.render();
        return this;
    },
    ...
});