简体   繁体   中英

Backbone/Javascript remove element from dom

I have a page with two div classes which is fine. One is the collection the other the item.

But when i want to select edit, i need to remove the item view and replace it with the edit link, this is not happening and its staying there, below is my edit class would be great.

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

Can you post some more of the code? When you say 'edit link', do you mean something in the DOM, or a url in the address bar.

When you call @model.save, Backbone will automatically update the attributes of the model with attributes returned by the server, so the

@model = note

is not required. But if you are not binding the 'change' event on the model to anything, then the view will not update if the model changes.

Are you using Backbone routers to handle changes in the location.hash?

You can remove a view from the DOM by calling @remove() You could also call $(@el).replace(...) if you wanted to replace it with something.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM