Reputation: 4489
I try to execute operation "PUT" using Backbone. It fetchs the records from the server. But neighter where
nor get
method does retrieve a solution (result of console.log of code below is thus []
) which i can edit (using set
) and can save
.
Solution can be really simple but still don't realize what is wrong!
var Model = Backbone.Model.extend({
idAttribute : "ID"
});
var TodosCollection = Backbone.Collection.extend({
model : Model,
url : myUrl
});
var todos = new TodosCollection();
todos.fetch();
var todo = todos.where({
ID : 2
});
console.log(todo);
todo.set('Name', 'ChangedName');
todo.save();
Upvotes: 0
Views: 40
Reputation: 196
You need to Parse the response and specify where your models are.
For better reference if someone stumbles on this. This could look something like
{
"location": "UK",
"users": [
{id: "etc", name: "etc"},
{id: "etc", name: "etc"},
{id: "etc", name: "etc"}
]
"someothermeta": "score",
"foo": "bar"
}
Your parse function will then be:
parse: function(response) {
return response.users;
}
Upvotes: 1