2013-03-04 34 views
0

我是Backbone的新手,我試圖單擊工具欄上的按鈕(位於工具欄div上),該按鈕被稱爲「新建」。 單擊後,我想要在id =「app-list」的另一個div上打開一個新面板。如何在主幹上創建嵌套模板

但在新的按鈕按下時,它總是覆蓋「的應用程序列表」 DIV

這裏是我的代碼(我使用的骨幹網和CoffeeScript的):

class MyApp.Views.ToolbarAppView extends Backbone.View 
    el: "#toolbar-app" 

    events: "click #add_new": "newApp" 

    newApp: (e) -> 
    myapp = new MyApp.Models.App 
    @model = myapp 
    newPanel = new MyApp.Views.NewAppView({ el: @$el, model: @model, parent: @}) 
    newParent.render() 

class MyApp.Views.NewAppView extends Backbone.View 
    template: JST["myapp", "new_app_view"] 

    render: -> 
    fieldsPanel = new MyApp.Views.EditAppView({ el: @$el, model: @model, parent: @}) 
    fieldsPanel.setElement('#app-list').render() 



class MyApp.Views.EditAppView extends Backbone.View 
    template: JST["myapp", "edit_app_view"] 
    tagName: "tr" 
    className: "edit_data" 

    render: -> 
    @$el.html(@template({ el: @$el, model: @model, parent: @}) 

回答

0

不知道你怎麼HTML結構看起來,推斷可能是什麼問題並不容易。然而,有一些有趣的事情在這裏這兩條線:

fieldsPanel = new MyApp.Views.EditAppView({ el: @$el, model: @model, parent: @}) 
fieldsPanel.setElement('#app-list').render() 

在你設置視圖的elToolbarAppViewel構造,並在下一行更改元素到另一個。

嘗試用以下替換兩行:

fieldsPanel = new MyApp.Views.EditAppView({ el:'#app-list', model: @model, parent: @}) 

如果失敗,考慮更多信息編輯你的問題,特別是關於你的HTML模板的相關部分。