Backbone parsing json response

前端 未结 2 776
走了就别回头了
走了就别回头了 2021-02-09 20:58

I\'ve been using Backbone for a total of 3 days now, and I can see that this has been asked about quite a lot, but honestly I\'m just not getting it. I\'ve been banging my head

2条回答
  •  离开以前
    2021-02-09 21:35

    You should use the parse() method in your collection :

    Contact.Collections.Employees = Backbone.Collection.extend({
        model: Contact.Models.Employee,
        url: "includes/test-data.json",
    
        initialize: function(){
            console.log("Employees initialize");
        },
    
        parse : function(response){
            return response.employees;  
       }    
    
    });
    

    There is one parse() in the MOdel as well as in the Collection, for the same purpose on url() handling.

    EDIT : I'm not an expert in the Router, but I suppose you have to render the View at some point.

    var view = new Contact.Views.Employees({ collection: Contact.employees }); 
    view.render();
    

提交回复
热议问题