backbone js, Update view on model change

前端 未结 3 1109
挽巷
挽巷 2020-12-25 09:44

Why my view is not getting updated?

    

     
     

        
3条回答
  •  暖寄归人
    2020-12-25 10:19

    You were missing a few things.

    • The row template should only render one row. The Table template repeats it in collection.each().
    • You needed to specify which model the View was tied to. Now, when the model is changed, the View "listens to" that event and fires its render action. Note that you didn't specify a model, but the collection auto creates a model for each element in the data array it's passed.
    • You were trying to use setElement for rendering the view. Rendering is as simple as passing your template's HTML to the jQuery object which is auto created by the view (this.$el in code below).
    
        
        
        
        
        
        
    
    

提交回复
热议问题