首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >嵌套视图骨干网

嵌套视图骨干网
EN

Stack Overflow用户
提问于 2014-04-19 12:13:42
回答 1查看 71关注 0票数 0

我正在尝试做一个嵌套视图。Backendview调用另一个视图Listpostview,但不起作用,我在嵌套视图Liastpostview中插入了一个console.log,以查看它是否被调用,但从未打印。

外部视图代码如下:

代码语言:javascript
复制
var BackendView = Backbone.View.extend({

    tagName: "p",

    events: {
      "touchend": "goToDetails"
    },

    template: Handlebars.compile(template),

    initialize: function () {

      this.model.bind("change", this.render, this);
      this.model.bind("destroy", this.close, this);
    },

    render: function (eventName) {


    console.log(this.model);


    var list=new ListPostView({model:this.model});
    list.render();

      return this;
    },


  });

return BackendView;

});

这是上面视图调用的ListPostView代码:

代码语言:javascript
复制
var ListPostView = Backbone.View.extend({

    tagName: "ul",
    id: "list",

    template: Handlebars.compile(template),

    initialize: function () {
        console.log(this.model);
      this.model.bind("reset", this.render, this);
    },

    render: function (eventName) {
    console.log("dddd"+this.model);<---this console.log will never called!?
      $(this.el).empty();
      _.each(this.model.models, function (ad) {
        $(this.el).append(new SinglePostView({
          model: ad
        }).render().el);
      }, this);
      return this;
    }
  });

return ListPostView;

 });  

最后,上一次视图调用的视图代码:

代码语言:javascript
复制
var SinglePostView = Backbone.View.extend({

    tagName: "li",

    events: {
      "touchend": "goToDetails"
    },

    template: Handlebars.compile(template),

    initialize: function () {
        //console.log(ad);
      this.model.bind("change", this.render, this);
      this.model.bind("destroy", this.close, this);
    },

    render: function (eventName) {
      var ad = this.model.toJSON();
      ad.cid = this.model.cid;
      $(this.el).html(this.template(ad));
      console.log(this.template(ad));

      return this;
    },


  });

return SinglePostView;

 });
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-06 00:38:02

在调用BackendView呈现方法之后,它看起来不像是在使用BackendView变量。

我看到调用了list.render(),但这并不能将list.$el元素插入到任何地方的DOM中。我要测试的第一件事是使用BackendView调用this.$el.append(list.$el)中的呈现方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23169924

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档