Domanda

Here is my data that has to be rendered:

var data = {
    "foo" : "1",
    "project": [
        {
            "name": "Project 1",
            "status": "red"
        },
        {
            "name": "Project 2",
            "status": "green"
        },
        {
            "name": "Project 3",
            "status": "red"
        }
    ]
};

I want to loop through this data and print projects with status red, yellow, and green separately. If there is no project of particular status type then I want to display no yellow/red/green project. I am able to display the projects under their particular status but how do I find whether there is no project of the current status type.

My dust template is:

<h1>red</h1>
{#project}{@eq key=status value="red"}{name}
{/eq}{/project}
<h2>green</h2>
{#project}{@eq key=status value="green"}{name}
{/eq}{/project}
<h2>Yellow</h2>
{#project}{@eq key=status value="yellow"}{name}
{/eq}{/project}

Please see: http://jsfiddle.net/xuLSq/

È stato utile?

Soluzione

I'm not absolutely sure, but DustJS doesn't support this use case.

Since it's a templating engine, I guess they encourage you to expose plain data in your model and avoid such kind of logic in the template itself.

You might split your model as follows:

  • redProjects
  • greenProjects
  • yellowProjects

And then you won't require DustJS syntax to get this working!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top