【问题标题】:Fetching node view to be used in backbone view获取要在主干视图中使用的节点视图
【发布时间】:2013-12-28 14:03:18
【问题描述】:

我正在开发一个中大型节点/骨干应用程序。出于这个原因,我自己和与我一起工作的其他开发人员决定使用节点视图来保持我们的代码干净。

任何有关获取视图并将其渲染到主干视图所需的信息都会非常有帮助。

非常感谢。

-迈克

【问题讨论】:

    标签: javascript node.js backbone.js


    【解决方案1】:

    如果您使用节点为骨干网提供模板,每个模板都有一个路由,您最终可能会收到很多并行请求。

    无论如何,您都可以按照此处所述异步加载模板:http://lostechies.com/derickbailey/2012/02/09/asynchronously-load-html-templates-for-backbone-views/

    Backbone.View.extend({
      template: 'my-view-template',
    
      render: function(){
        var that = this;
        //fetch your template from whereever
        $.get("/templates/" + this.template, function(template){
          var html = $(template).tmpl();
          that.$el.html(html);
        });
        return this;
      }
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-20
      • 2012-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多