Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/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 将下划线变量与主干样板文件fetchTemplate函数一起使用_Backbone.js_Underscore.js - Fatal编程技术网

Backbone.js 将下划线变量与主干样板文件fetchTemplate函数一起使用

Backbone.js 将下划线变量与主干样板文件fetchTemplate函数一起使用,backbone.js,underscore.js,Backbone.js,Underscore.js,我正在使用构建一个应用程序,在使用下划线模板变量时遇到一些问题。我有一个名为Goal的资源。我的目标视图的渲染函数如下所示: render: function(done) { var view = this; namespace.fetchTemplate(this.template, function(tmpl) { view.el.innerHTML = tmpl(); done(view.el); }); } 我在另一个视图中称之为: var Goal =

我正在使用构建一个应用程序,在使用下划线模板变量时遇到一些问题。我有一个名为Goal的资源。我的目标视图的渲染函数如下所示:

render: function(done) {
  var view = this;

  namespace.fetchTemplate(this.template, function(tmpl) {
    view.el.innerHTML = tmpl();
    done(view.el);
  });
}
我在另一个视图中称之为:

var Goal = namespace.module("goal"); 

App.View = Backbone.View.extend({

  addGoal: function(done) {

    var view = new Goal.Views.GoalList({model: Goal.Model});

    view.render(function(el) {
      $('#goal-list').append(el);
    });
  }
});
我正在使用本地存储来保存我的数据,而且添加得很好。我可以在浏览器中看到它,但由于某种原因,当我加载应用程序并尝试获取现有数据时,我遇到以下错误:

ReferenceError: Can't find variable: title
其中title是我存储的唯一密钥。这是调用以下命令的直接结果:

tmpl();

非常感谢您的任何想法。

您的模板正在寻找一个变量
标题
,可能是这样的
。您需要像这样向它传递一个对象
tmpl({title:'Some title'})

结果是,我在创建视图时没有传递模型,这使得无法获取模型数据。一旦我正确地传递了模型,我就可以将数据传递给tmpl,正如@abraham所正确说明的那样

render: function(done) {
    var 
    view = this,
    data = this.model.toJSON(); 

    clam.fetchTemplate(this.template, function(tmpl) {

    view.el.innerHTML = tmpl(data);

    done(view.el);
    });
},

代码中必须有一个变量
title
。是否没有与错误消息关联的行号?