2012-01-30 59 views
0

刪除元素我有兩個DIV類這是很好的一個頁面。一個是收集另一個項目。骨幹/ javascript中的DOM

但是,當我想選擇編輯,我需要刪除的項目視圖,並在編輯鏈接替換它,這是不會發生及其呆在那裏,下面是我的編輯類將是巨大的。

Supernote.Views.Notes ||= {} 



class Supernote.Views.Notes.EditView extends Backbone.View 

template : JST["backbone/templates/notes/edit"] 



events : 

"submit #edit-note" : "update" 



update : (e) -> 

    e.preventDefault() 

    e.stopPropagation() 



    @model.save(null, 

    success : (note) => 

    @model = note 

    window.location.hash = "/#{@model.id}" 

) 



    render : -> 

    $(@el).html(@template(@model.toJSON())) 



    this.$("form").backboneLink(@model) 



    return this 

回答

0

你能發表一些更多的代碼嗎?當你說'編輯鏈接'時,你的意思是DOM中的東西,或者是地址欄中的網址。

當你調用@ model.save,骨幹會自動更新服務器返回的屬性模型的屬性,所以

@model = note 

不是必需的。但是,如果您沒有將模型上的「更改」事件綁定到任何事物,那麼如果模型更改,視圖將不會更新。

您使用的骨幹路由器來處理中的location.hash變化?

您可以通過調用@remove() 從DOM中刪除視圖如果您想用某種東西替換它,也可以調用$(@ el).replace(...)。