0

I have a JArray that contains an array of objects. I am using handlebars.net to bind the data in the template.

In getReportDetails variable, I am getting an array of objects in the below format:

[
    {
        "index": 1,
        "Name": "Adam",
    },
    {
        "index": 2,
        "Name": "Sdam",
    }
];

var template = Handlebars.Compile(source);
_logger.Info(getReportDetails);
var getdata = template(getReportDetails);

<tbody>
    {{#each getReportDetails}}
    <tr>
        <td>{{Name}}</td>
    </tr>
</tbody>

In getdata variable data is not binding.

1 Answer 1

2

Your array is root of your data object, so you should use #each this:

<tbody>
    {{#each this}}

Working example:

    var list = new List<X>() { new X() { Id=1 }, new X() { Id = 2} };
    var template = Handlebars.Compile("{{#each this}} xxx {{Id}} {{/each}}");
Sign up to request clarification or add additional context in comments.

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.