how to check true condition in iCanHaz (Moustache Template engine)

444 views Asked by At

I've this json return

data = [
    {   firstName: "Christophe",
        lastName: "Coenraets"},
    {   firstName: "John",
        lastName: "Smith"}
];

I want to display each object in a li list and want to use Enumerable condition. I understand if it'd been like

data = { elem :[
        {   firstName: "Christophe",
            lastName: "Coenraets"},
        {   firstName: "John",
            lastName: "Smith"}
]};

I can use something like

{{#elem}}
    <li>{{firstName}} {{lastName}}</li>
{{/elem}}

But in the first case, how do I check the condition?

1

There are 1 answers

0
dbrin On BEST ANSWER

I don't work with icanhaz, it very well may have a method to parse the data that you get, but you could always modify the JSON object and wrap it into a parent element like in your second case:

myData = { elem : data};