我有一個div容器元素,在這個容器元素中我有多個模板。我想根據從後端返回的json有選擇地加載模板。這是一個微不足道的問題,但面臨着這些問題。一些邏輯代碼。Backbone.js視圖+ underscore.js模板
<div id = "container">
<div class = "row page">
<script type = "text/template" id = "template1">
<div id = "template1_id">
</div>
</script>
<script type = "text/template" id = "template2">
<div id = "template2_id">
</div>
</script>
</div>
</div>
在我的骨幹查看我在做這樣的事情:
var someView = Backbone.view.extend({
el: '.page'
render: function() {
el: '.page';
var template1 = _.template($('#template1').html());
this.$el.html(template1);
//get Json from backend and render the template within the fetch method
var collection1 = new someCollection();
someCollection.url = "blah";
someCollection.fetch (function() {
success: function() {
var template2 = _.template($('#template2').html());
$('#template1_id').html(template2);
}
});
},
});
只有第一個模板被渲染,而不是第二個。我在這裏做一些根本性的錯誤嗎?
謝謝你。對我來說太愚蠢了。 – 2013-03-14 08:20:15