1

我在Requirejs中使用了Backbone.js和underscore.js。但是,当我尝试加载我的视图模板,它给我(8超出范围6)错误在Underscore.js第8行。 请告诉我我做错了什么。(8超出范围6)Underscore.js模板

这里是我的代码:

var imageView = new ImageView({model: item}); 


define(['jquery','underscore','backbone','imageview','text!../templates/template_image.html'], 
function($, _, Backbone, ImageView, template){ 
     var ImageView = Backbone.View.extend({ 
      initialize: function(){ 
       this.showImageTemplate = _.template(template);    
      }, 
      render: function(){ 
       var html = this.showImageTemplate(this.model); 
       this.$el.html(html); 
       return this; 
      } 
     }); 
    return ImageView; 
}); 

我的模板文件:

<img id="frameImg" src="<%= DocumentPath %>/<%= DocumentName %>" alt="image" title="image"/> 
+0

此外,当我尝试CONSOLE.LOG(this.model)的渲染功能,它让我看到我的完整的模型,但我得到的错误,当我运行我的代码: 的ReferenceError:DocumentPath没有定义(8超出范围6) PS。 DocumentPath包含在型号 – xTMNTxRaphaelx

回答

1

你传递的原始Backbone.Model对象作为数据到您的模板,所以你喜欢的东西的工作

{  
    _changing: false, 
    _pending: false, 
    _previousAttributes: {} 
    attributes: { 
     DocumentPath: "", 
     DocumentName: "" 
    } 
    ... 
} 

您可能只想要属性,您可以通过例如,。尝试:

var html = this.showImageTemplate(this.model.toJSON()); 
+0

谢谢,这是这个问题。我以前没有意识到我的错误。 现在正在工作,再次感谢:) – xTMNTxRaphaelx