问题
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...
回答1:
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});
来源:https://stackoverflow.com/questions/18347533/filtering-a-collection-in-titanium-alloy