Skip to content Skip to sidebar Skip to footer

Backbone Collection View Add Not Being Called With A Model

I've my models var Client = Backbone.Model.extend({}); var Colony = Backbone.Collection.extend({ url: '/presence/knock', model: Client }); views var ClientView = Backbone

Solution 1:

I think i figured out your problem.

Here is a working fiddle with your code: http://jsfiddle.net/nilgundag/KbwHZ/

I have used mockjax to mock the server and here what it returns:

[{
    ip: '127.0.0.1',
    name: 'localhost.localdomain',
    lsup: 'now'
},
{
    ip: '127.0.0.2',
    name: 'localhost.localdomain',
    lsup: 'now'
}]

Since you said you are getting Object {clients: Array[1]}, probably your server returns:

[{
        clients:[{
                ip: '127.0.0.1',
                name: 'localhost.localdomain',
                lsup: 'now'
        }]
}]

Here is fiddle which demonstrates your case: http://jsfiddle.net/nilgundag/TxZxp/

You should change your server code to only send the client array, not an object containing a property clients and the associated array.

Post a Comment for "Backbone Collection View Add Not Being Called With A Model"