내 모델의 데이터를 가져 오는 백본에서 내 뷰를 렌더링 할 때 몇 가지 문제가있어 도움을 주시면 감사하겠습니다. 여기 내 html 코드 진행됩니다백본에서 모델의 데이터를 가져 오는 템플릿 렌더링
<ul id="datos">
</ul>
<script type="text/template" id="listado-template">
<h2>Mi listado</h2>
<li>Item 1: <%= item1 %></li>
</script>
<script>
modelo = new Modelo();
modeloView = new ModeloView({model: modelo});
</script>
을 그리고 이것은 내 모델과 내 볼 수 있습니다 :
Modelo = Backbone.Model.extend({
urlRoot: 'myurljson',
});
Backbone.View.extend({
tagName: "ul",
el: "#datos",
template: _.template($('#listado-template').html()),
initialize: function() {
this.model.on('change', this.render, this);
},
render: function() {
this.$el.append(this.template(this.model.toJSON()));
return this;
}
});
문제는 내 템플릿이 잘 renderized되지이다. item1
으로 정의되지 않은 오류가 나타납니다. 그러나이 태그 li
을 삭제하면 h2
태그가 렌더링되므로 문제는 "myurljson"을 통해 내 모델에서 내 데이터를 가져 오는 것입니다. 어떤 도움이 필요합니까? 고맙습니다!
당신은'모델을 fetch'습니까? –
예. 이 백본을 렌더링 할 때'modelo.fetch'를 수행합니다.보기 – akruspe