خرید بک لینک

Vote count: 0

I am trying to understand how a collection passed in to a view is being referenced and used. There does not seem to be any reference to the collection, but it's models are being used. Also, I'm unable to get the collection items to be bound/displayed when I use my collection that is bound to my api, but it works when I use the hard coded collection. Is it because I need to fetch my collection at some point? My collection is fine and the path is fine. I use it throughout my app without any problems.

Below is the code:

module.exports = Backbone.Collection.extend({

    model: Employee,

    url:"api/employees"

});

MainView

 module.exports = base.extend({
      el:  '#content',
      template:template,
        initialize: function () {

            // var items = new EmployeeCollection([
            //     {id: 1, firstName: "Test1 fName", lastName: "Test1 lName"},
            //     {id: 2, firstName: "Test2 fName", lastName: "Test2 lName"},
            //     {id: 3, firstName: "Test3 fName", lastName: "Test3 lName"}
            // ]);

            EmployeeListCollection = new EmployeeCollection();
            //this.itemView = new EmployeeListView({collection: items}); //this syntax works if I uncomment the code above to create my item list
            this.itemView = new EmployeeListView({collection: EmployeeListCollection}); //do i need to fetch the collection at some point?

            this.render();

          },
          render: function(){

            this.el.ierHTML = Mustache.to_html(this.template);

            this.itemView.render();

            $("#empList").html(this.itemView.el);
          }
});

ItemListView - where does the passed in collection get referenced? I see a model reference, but I passed in a collection.

module.exports = base.extend({

    //tagName:'ul',
    tagName:'select',

    initialize: function(){
        _.bindAll(this, "renderItem");

    },

    renderItem: function(model){
        console.log('employeelistloop render');

        this.itemView = new EmployeeListItemView({model: model});
        this.itemView.render();
        $(this.el).append(this.itemView.el);
    },

    render: function(){
        this.collection.each(this.renderItem);
    },

});

asked 30 secs ago

- - , .
.

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 20 تير 1395 ساعت: 21:37

صفحه بندی