0

From one controller (Convos) I fire up a Messages controller. I pass in an id, and am trying to use that id to filter which Messages are bound to the new view. For some reason, the filtering is not working, and all Message records are being shown. Here's the code in my Messages controller.

Data structure for the Messages model

message_id: "integer",
convo_id: "integer",
created: "text",
author: "text",
body: "text",

Convos.js

var messages = Alloy.createController('messages', { 
    convoId: e.rowData.convoId,
});
messages.getView().open();

Messages.js

var args = arguments[0] || {}

var messages = Alloy.Collections.messages;
messages.reset();
messages.fetch();
messages.where({convo_id: args.convoId});

Am I doing anything obviously wrong? Titanium's docs regarding Alloy are scant, and the Backbone docs seem to assume you know how to use it already...

Benjamin Allison
  • 2,134
  • 3
  • 30
  • 55

1 Answers1

2

the where function returns an array of models, if does not update the actual collection

http://backbonejs.org/#Collection-where

var filteredArray = messages.where({convo_id: args.convoId});
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80
  • Ohhhhh! For some reason I assumed that calling a method on the collection would execute that on the collected data. This behaviour seems inconsistent. For example, `collection.reset()` **does** reset the collection; you don't have to go `resetCollection = collection.reset()`. Grr. So, how do I go about binding my view to the filtered data? AFAIK I can only bind my TableView to a collection. Anyway, thanks Aaron! – Benjamin Allison Aug 22 '13 at 13:23
  • you want to do the filtering in the filter method specified in the view binding. scroll down to the section on dataFilter http://docs.appcelerator.com/titanium/latest/#!/guide/Alloy_Data_Binding-section-36739592_AlloyDataBinding-AlloyModel-ViewBinding – Aaron Saunders Aug 22 '13 at 22:32