在我的應用程序中,我有幾個tagList
,每個包含幾個tags
分組由index_name
。如何使用Backbone.js處理嵌套視圖?
我很遺憾應該如何處理Backbone視圖。
我有一個TagListView
延伸Backbone.View
,我想我會處理所有這個視圖的事件。
我的主要問題我應該創建一個TagView
與渲染功能,將創建&爲每個標記呈現在TagListView
渲染功能?
以下是我在我看來,到目前爲止做的:(這是正確的初始化?!)
<ul id="strategy-tags">
<!-- initial data -->
<script type="text/javascript">
AppData.strategyTagList = $.parseJSON('<?php echo json_encode($strategyTagList); ?>');
strategyTagListView = new App.TagListView({el : "#strategy-tags", data: AppData.strategyTagList});
</script>
</ul>
裏面我core.js
:
App.TagListView = Backbone.View.extend({
// dom event specific to this item.
events: {
},
initialize: function(options) {
this.el = options.el;
},
render: function() {
// let's construct the tag list from input data
_.each(options.data, function(index) {
// render index? <-- how ?
_.each(index, function(tag) {
// render tag? <-- how ?
console.log(tag);
});
});
return this;
}
});
非常感謝。