简体   繁体   English

从骨干模板上的集合中获取数据

[英]Fetching data from collection on backbone template

HI i am writing a simple Backbone program. 您好,我正在编写一个简单的Backbone程序。 i have written simple code to fetch data from collection on to the backbone template. 我已经编写了简单的代码来从集合中提取数据到主干模板。 But i am getting error Uncaught SyntaxError: Unexpected token < 但是我遇到了错误Uncaught SyntaxError:意外令牌<

here is my collection code: 这是我的收藏代码:

var Album = Backbone.Collection.extend({

        url : "/data.json"
      });

this is my view code 这是我的查看代码

var UserList= Backbone.View.extend({
el:'.page',
template:_.template($('#user-list-template').html()),
render : function(){
 var that=this;
 var album= new Album();
 album.fetch({
  success:function(album){
   alert("data fetched from collection");
   var _data = {data : album.models} ;
   $(that.el).html(that.template(_data));
  }
 })
}
});

and i am fetching data here: 我在这里获取数据:

<script type="text/javascript" id="user-list-template">
       <h1> <%= data.key %> </h1>

  </script>

Your template should be something like 您的模板应类似于

<script type="text/template" id="user-list-template">

It cannot be of type javascript , because it isn't javascript... Hence the syntax error. 不能javascript类型,因为它不是javascript ...因此语法错误。

Your Template cannot be of type javascript, because it isn't javascript. 您的模板不能为javascript类型,因为它不是javascript。 It should be like 应该像

<script type="text/template" id="user-list-template">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM