钛合金过滤集合 [英] Filtering a collection in Titanium Alloy

查看:300
本文介绍了钛合金过滤集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从一个控制器(Convos)我火了一个消息控制器。我传递一个ID,并正尝试使用该ID来过滤消息被绑定到新的看法。出于某种原因,过滤不工作,并正在显示的所有信息记录。这里是我的消息控制器code。

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.

的消息模型中的数据结构

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...

推荐答案

在哪里函数返回的模型数组,如果不更新实​​际收集

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});

这篇关于钛合金过滤集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆