28

I've this json return

{
    "timeline": [{
        "id": "2",
        "self": {
            "uid": "2",
            "username": "ptamzz"
        },
        "file": {
            "fid": "43",
            "file_name": "First Name"
        },
        "connection": {
            "fid": "4",
            "username": "tom"
        },
        "action": "viewed your document",
        "time": "2012-01-16 12:23:03",
        "tags": ["Engineering", "Computer Science", "Java", "Java Library"]
    }, {
        "id": "1",
        "self": {
            "uid": "2",
            "username": "ptamzz"
        },
        "file": {
            "fid": "41",
            "file_name": "Write Up"
        },
        "connection": {
            "fid": "4",
            "username": "tom"
        },
        "action": "favorited your document",
        "time": "2012-01-16 12:22:04",
        "tags": ["Design"]
    }]
}

According to the tutorial at http://coenraets.org/blog/2011/12/tutorial-html-templates-with-mustache-js/ (Sample 6: Nested Object section), you can access dot notation to access the nested objects.

From the above json, I want to retrieve the data like self.username, file.file_name etc etc.

Now, I've my template as

{{#timeline}}
    <li>
        {{self.username}}
    </li>
{{/timeline}}

But self.username doesn't work.

How do I retrieve these nested values?

2 Answers 2

28

I don't think it's the right way to do but since I couldn't find any answers here, I figured out something myself. At least this works.

{{#timeline}}
    <li>
        {{#self}}{{username}}{{/self}}
    </li>
{{/timeline}}
Sign up to request clarification or add additional context in comments.

4 Comments

dot notation DOES work. There must be an error in your special case. Maybe because "self.username" is in an array and can appear several times.
i cant get the "dot notation" working for a simple object. =( eg. card { id:10, name: "maxwell" }
Doesn't this depend on the actual processor?
Check your version number. stackoverflow.com/questions/9347998/…
6

Dot notation does not work on version 0.4x and below. It worked on "0.7.2".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.