Filtering a collection in Titanium Alloy

你离开我真会死。 提交于 2019-12-13 05:22:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!