Flame
Flame

Reputation: 7580

Backbone where returns empty in fetch callback

I'm having an odd error where a backbone where function (Titanium Alloy, kinda homogeneous) returns empty while the fetch method returns a list of models. Ive checked over and over again, I tried putting the where function in the success callback of the fetch method but STILL it results in an unresolvable error

Alloy.Collections.favorites.fetch({
     success: function(collection) {
          console.log(JSON.stringify(collection));
          console.log(self.get('id'));
          var favorite = collection.where({
              jobId: self.get('id')
          });
          console.log(JSON.stringify(favorite));
});

The above output is:

[{"jobId":5162179,"dateAdded":1414590144,"candidateId":99,"id":19},{"jobId":5161302,"dateAdded":1414588983,"candidateId":99,"id":17},{"jobId":5161437,"dateAdded":1414588785,"candidateId":99,"id":16}]
5161437
[]

How can the above happen? How can somebody reproduce this? Is the collection being occupied or is it a bug within Titanium Alloy? This process is part of a databind on a view (view A) and this exact code works on a different part where the only difference is that view A is not directly influenced by changes in the collection.

Any help? Is this even possible with backbone? I cant get my head around this

Upvotes: 1

Views: 348

Answers (1)

Flame
Flame

Reputation: 7580

APPARENTLY the .where function strictly compares 2 values (=== operator) and the id i gave was in the form of a string while the id within the collection was an integer. Too bad the backbone documentation doesnt state this information

Upvotes: 2

Related Questions