Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带下划线文本模板的backbone.js_Backbone.js - Fatal编程技术网

带下划线文本模板的backbone.js

带下划线文本模板的backbone.js,backbone.js,Backbone.js,是否有人有使用Backbone.Epoxy(Epoxy.js)和通过模板传入的HTML的指针 aka给出了如下视图: define([ 'jquery', 'underscore', 'backbone', 'epoxy', 'text!views/MyTemplate.html' ], function($, _, Backbone, Epoxy, Template ){ var MyView = Epoxy.View.extend({ temp

是否有人有使用Backbone.Epoxy(Epoxy.js)和通过模板传入的HTML的指针

aka给出了如下视图:

define([
   'jquery',
   'underscore',
   'backbone',
   'epoxy',
   'text!views/MyTemplate.html'

], function($, _, Backbone, Epoxy, Template ){

var MyView = Epoxy.View.extend({

      template: _.template(Template),

      bindings: {
         ".brand-name": "text:name",      
         ".brand-name": "text:count",
      },

      // Perhaps render not needed given that epoxy bindings  
      render : function() {
         var data = {
           item: this.model,
          _: _ 
         };
         this.$el.html( this.template(data) );
         return this;
    }

  return MyView;

});
它呈现模板,但没有任何绑定


你还需要渲染方法吗

不,您不需要render方法,只需实例化视图即可

var view = new BindingView({model: bindModel});

但是,当使用render方法并替换view.el时,会丢失这些绑定,在这种情况下,请尝试执行以下操作:

this.$el.html( this.template(data) );
this.applyBindings();

谢谢在这种情况下,主干/环氧代码与html合并。我指的是通过“文本”传递html的情况!views/MyTemplate.html'似乎可以使用主干'el'。