Javascript 尝试实例化子视图的parentView中的backbone.js uncaught typeError

Javascript 尝试实例化子视图的parentView中的backbone.js uncaught typeError,javascript,backbone.js,view,render,Javascript,Backbone.js,View,Render,我正在尝试为parentView调试此代码。此代码引发的错误是“UncaughtTypeError:无法读取未定义的属性'attributes'。console.log也返回为未定义,但是如果我console.log稍后在渲染函数中与this.model.total_fans相同,则它有一个值。我不太了解主干网,无法调试这个令人烦恼且可能很小的错误,但我觉得这种设置方式有点错误,特别是在阅读了有关在masterview中渲染子视图的文章之后。我想知道这里到底出了什么问题。我应该在父视图中实例化子

我正在尝试为parentView调试此代码。此代码引发的错误是“UncaughtTypeError:无法读取未定义的属性'attributes'。console.log也返回为未定义,但是如果我console.log稍后在渲染函数中与this.model.total_fans相同,则它有一个值。我不太了解主干网,无法调试这个令人烦恼且可能很小的错误,但我觉得这种设置方式有点错误,特别是在阅读了有关在masterview中渲染子视图的文章之后。我想知道这里到底出了什么问题。我应该在父视图中实例化子视图吗?父级是否应该在模型更改时调用render和pagesetup

initialize:function () {
    var self = this;

    // General model for this page
    this.model = new geodemoModel();

    // separate summary model
    this.summaryModel = new summaryModel();

    this.model.fetch();
    this.summaryModel.fetch();

    this.model.bind('change', this.render, this);
    this.model.bind('change', this.pageSetup, this);

    this.summaryModel.bind('change', this.render, this);
    this.summaryModel.bind('change', this.pageSetup, this);

  },

pageSetup:function () {
 if (this.oneSelect == 'All' || this.oneSelect == 'lifetime_fans') {
        console.log(this.model.total_fans);
        var viewLifetime = new lifetimeView(this.model.total_fans.attributes.total_fans_object);
        $('#lifetimeFans').html(viewLifetime.render().el);
      }

假设您的模型存在,您应该使用:

this.model.get('total_fans').attributes.total_fans_object
如果这不起作用,请在
pageSetup
中粘贴
console.log(this.model)

子项{cid:“c7”,属性:Object,_changing:true,_previousAttributes:Object,changed:Object…}_更改:true _事件:对象_挂起:false _上一个属性:对象属性:对象日期:对象上一个:对象选定:对象原型:对象更改:对象cid:“c7”查询参数:对象顶部\u参与\u按国家\u 28:儿童顶部\u参与\u人口统计\u 28:儿童顶部\u粉丝\u按国家\u 28:儿童顶部\u粉丝\u人口统计\u 28:儿童顶部\u到达\u按国家\u 28:儿童顶部\u到达\u人口统计\u 28:儿童总粉丝\u粉丝\u演示:儿童