I have backbone function that get data via a node.js server with MongoDB. I am doing a fetch and getting all the data back fine, but it does note seem to filter it based on the data request in the fetch statement:
getItems: function (listId)
{
this.list = new List({_id: listId});
this.list.fetch();
console.log(listId);
console.log(this.list);
this.itemCollection = new ItemCollection();
this.itemView = new ItemView({model: this.itemCollection},this.list);
this.itemCollection.fetch({data: { list: listId }, processData:true}); // << THIS IS PROBLEM LINE
console.log(this.itemCollection);
return this.itemView;
},
My item collection is:
define(['jquery', 'underscore', 'backbone', 'model/ItemModel'
], function($, _, Backbone, Item){
var ItemCollection = Backbone.Collection.extend({
model: Item,
url: "/api/items"
});
return ItemCollection;
});
My Item Model is: define([ 'jquery', 'underscore', 'backbone' ], function($, _, Backbone){
var Item = Backbone.Model.extend({
urlRoot: "/api/items",
defaults: {
name: "",
done: false
},
idAttribute: "_id"
});
return Item;
});
My Node API is:
app.get('/api/items', function (req, res) {
return ItemModel.find(function (err, item) {
if (!err){
return res.send(item);
} else {
return console.log(err);
}
});
});
Hope that's enough info to give you and idea of what I'm trying to do. At the moment I am getting every item back from the database, not just the items with the correct listId.
Thanks for any help.