问题
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.
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.
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.
I want to get a JSON from a web-service and either do one of the following, whichever is easier:
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 ) 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
}
Binding a Collection to a TableRow, no problem. Storing records, no problem. This kind of associative, nested binding stuff... kicking my ass.
回答1:
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
来源:https://stackoverflow.com/questions/18017901/confused-about-working-with-nested-models-in-titanium-alloy