javascript - Backbone underscore where returning empty array -


The app rails with the backbone on the foreground. Many articles have been saved in my databases. But they have a publication_id also what I want to do is catch every article with a special publication. I can have several articles related to any given publication_id I am trying to use underscores. The function that comes with backbone.

  delete_publication: function (id) {var articles = new MyProject.Collections.Articles (); Console.log (article where {{publication_id: id}); }  

Edit: In this version, if I just receive the console.log article:

  child {length: 0, model: array [0], _bid: object, constructor: function, url: "/ article" ...}  

The goal is to eventually capture the model, remove them from the database Update and then update accordingly Now for now I want to print a subset of those articles which have a specific publication, IID, it's just the console The new Chhapti an empty array.

I have also tried:

  delete_publication: function (id) {var articles = new MyProject.Collections.Articles); Articles.fetch ({Success: Function (data) {console.log (data. Where ({publication_id: id}));}}); }  

Edit: In this version, if the console.log only finds articles:

  child {length: 23} , Model: array [23], _bid: object, constructor: function, url: "/ article" ...}  

which prints an empty array. I know that I want the database to be in the database, so if I do the right thing then I should not get the empty array back.

How do I use _ to capture my subset of the archive? Also open for better ways. Hope this answer will be clear to anyone else!

Solution! *

delete_publication: function (id) {var articles = new SimpleGoogleReader.Collections.Articles (); Articles.fetch ({Success: Work (data) {_.each (data.moles, function (item) {if (item.toJSON (..publicication_id == ID) {console.log (item.toJSON ()); } // console.log (item.toJSON (). Publication_id);});}}); }

Rida Bennahman does again! The above code only consolves the Jason object of those articles.

This is the second method to work with success callback, just check that publication_id is set to the returned model:

  _each (data.models, function (item) {if (item.publication_id) {console.log (item);} });  

Comments