0
backbone.js를 처음 사용합니다. 구문 분석하고 내가 가지고있는 템플릿을 채우는 JSON 문자열을 얻으려고합니다.backbone.js json -> template
JSON :
[
{
"nav":{
"feel":"Feel Well",
"eat":"Eat Well",
"move":"Move Well",
"work":"Work Well",
"sleep":"Sleep Well",
"play":"Play Well"
}
}
]
CODE :
//collection
WH.ApplicationCollection = Backbone.Collection.extend({
defaults: {
model: WH.ApplicationModel
},
model: WH.ApplicationModel,
url: 'json/test.json'
});
// View
WH.applicationView = Backbone.View.extend({
el: 'body',
template: _.template($('#header-template').html()),
initialize: function(){
this.collection = new WH.ApplicationCollection();
this.collection.bind("reset", this.render, this);
this.collection.fetch();
},
render: function(){
console.log(this.collection.toJSON());
$(this.el).html(this.template(this.collection.toJSON));
return this;
}
});
마크 업 :
<script id="header-template" type="text/template">
<div id="header">
<ul id="navigation">
<li id="logo"><a data-target="home" data-index="0" href="#/home"><h1></h1></a></li>
<% _.each(nav, function(navitem){ %>
<li><a data-target="<%= navitem %>" data-index="1" href="#/<%= navitem %>">Feel Well</a></li>
<% }); %>
</ul>
</div>
</script>
CONSOLE.LOG는 JSON 문자열이 판독되고 있음을 나타낸다. 그러나 그것이 실제 템플릿 일 때.
catch되지 않은 오류 ReferenceError가 : 탐색이 마크 업에서입니다
을 정의되지 않은 그것은 나에게 오류를 제공합니다.