lundi 1 février 2016

Cannot get vars displayed in my 'template' using Handlebars.js correctly

I have a Handlebars script that I am trying to get to iterate through an object to my 'template' below. Even though I can see the 'badNodes' in the object (an object when i do a console.log(row) it doesn't ever pass to the template and all I see is a blank entry next to address in the view/template.

Can anyone suggest what I may have done wrong - P.S I am new to Handlebars.js

<script class="template" type="text/html">
    <div class="badNodesContainer">
        {{#row}}
        <div class="hash{{badNodes.hash}} help-tip">
            <p>
                <strong>Address: </strong>{{badNodes.address}}</br>
            </p>
        </div>
        {{/row}}
    </div>
</script>

// latter part of ajax request

    .done(function (data, result, jqXHR) {
        var checkinData = JSON.parse(data).data;
        var rows = [];

        //_.templateSettings.variable = "badNode";
        var source = $("script.template").html();
        var template = Handlebars.compile(source);

        $.each(checkinData, function (index, row) {
                row.badNodesHTML = "";
                var AB_action_login = '<a class="btn btn-default btn-sm" style="width:70px;text-align:left;" target="_blank" href="http://ift.tt/1UDi11H' + row.user + '&hash=' + row.signature + '"><i class="fa fa-external-link"></i> App</a>';
                if (row.postid == null) {
                    var AB_action_order = '<a class="btn btn-default btn-sm hidden" disabled="disabled" style="width:70px;text-align:left;" target="_blank" href="http://ift.tt/1PQ6y0U' + row.postid + '&action=edit"><i class="fa fa-external-link"></i> Order</a>';
                } else {
                    var AB_action_order = '<a class="btn btn-default btn-sm" style="width:70px;text-align:left;" target="_blank" href="http://ift.tt/1PQ6y0U' + row.postid + '&action=edit"><i class="fa fa-external-link"></i> Order</a>';
                }
                row.AB_login = AB_action_login;
                row.AB_order = AB_action_order;
                row.AB_actions = AB_action_login + AB_action_order;

                if (row.badNodes.length) {
                    $.each(row.badNodes, function (idx, badNode) {
                        badNode.address.toString()
                        badNode.address = /:(.+)/.exec(badNode.address)[1];
                        row.badNodesHTML += template(badNode);
                        row.AB_actions;
                    });
                }
            }
        );



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire