对使用钛合金中的嵌套模型感到困惑 [英] Confused about working with nested models in Titanium Alloy

查看:111
本文介绍了对使用钛合金中的嵌套模型感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标很简单.我的应用程序具有消息传递组件.我计划构建它的方式是通过一个会话模型,该模型具有一些属性(主题,开始日期,uID),每个会话将包含许多消息模型.

The goal is simple. My app has a messaging component. The way I'm planning on structuring it is by having a Conversation model, which has some attributes (subject, start date, uID), and each Conversation will contain many Message models.

从概念上讲,我要尝试做的事情似乎微不足道:将对话集合绑定到TableView.单击表格视图后,嵌套的消息将绑定到新窗口.

Conceptually what I'm trying to do seems pretty trivial: have a Collection of Conversations bound to a TableView. When a table view is clicked, the nested messages get bound to a new Window.

我正在努力通过Backbone做到这一点.我在CakePHP和Knockout.js上具有MVx的经验,这种事情对他们来说是轻而易举的.骨干网的工作方式正在使我的大脑爆炸.

I'm struggling with how to do this via Backbone. I have experience with MVx with CakePHP and Knockout.js and this sort of thing is a breeze with them. The way Backbone works is exploding my brain.

我想从Web服务获取JSON,然后执行以下一项操作,以较容易的一项为准:

I want to get a JSON from a web-service and either do one of the following, whichever is easier:

1)获取具有嵌套模型的线程,并将消息绑定到新窗口:

1) Get a thread with nested models and bind the messages to a new Window:

"conversation": {
    "subject": "Subject",
    "created": "Jan 1, 2013",
    "uID": 1234,
    "messages": [
        {
            "author": "John",
            "created": "Jan 1, 2013",
            "content": "Some text.",
            "parent_id": 1234
        },
        {
            "author": "Steve",
            "created": "Jan 2, 2013",
            "content": "Some more text.",
            "parent_id": 1234
        }
    ]
}

2)分别抓取消息,并进行查询并将其绑定到新窗口.

2 ) Grab the messages separately, and do a query and bind that to the new Window.

Conversation

{
    "subject": "Subject",
    "created": "Jan 1, 2013",
    "uID": 1234,
}

Message

{
    "uID": 1,
    "author": "John",
    "created": "Jan 1, 2013",
    "content": "Some text.",
    "parent_id": 1234
}

Message

{
    "uID": 2,
    "author": "Steve",
    "created": "Jan 2, 2013",
    "content": "Some more text.",
    "parent_id": 1234
}

将Collection绑定到TableRow,没问题.存储记录,没问题.这种关联的,嵌套的绑定内容...踢我的屁股.

Binding a Collection to a TableRow, no problem. Storing records, no problem. This kind of associative, nested binding stuff... kicking my ass.

推荐答案

我使用 backbone associate取得了一些成功与Appcelerator Alloy一起使用.这是指向要点的链接,可以帮助您开始进行集成 http://bit.ly/12xyEyQ

I have had some success using backbone associate with Appcelerator Alloy. here is a link to a gist that can get you started with the integration http://bit.ly/12xyEyQ

这篇关于对使用钛合金中的嵌套模型感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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