0

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.

C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65
Benjamin Allison
  • 2,134
  • 3
  • 30
  • 55

1 Answers1

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

Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80