jquery display template with no data

1.7k views Asked by At

I have a template in jquery and trying to display just the HTML with no data. I tried to bind 'null' instead of the json "data" but it gives error (Address is undefined). Below is code statement.

$("#empTemplate").tmpl(null).appendTo("#divEmp");

HTML Markup:

<table style="padding-left: 5px">
            <tr>
                <td>
                    <span>Name:</span>
                </td>
                <td>
                    <span>Employer:</span>
                </td>
                <tr>
                    <td>
                        <table>
                            <tr>
                                <td>
                                    <span>1</span>
                                </td>
                                <td>
                                    {{if Address.Length >=1}}
                                    <input type="text" value="${Address[0].State}" style="width: 50px" />
                                    {{else}}
                                    <input type="text" value="" style="width: 50px" />
                                    {{/if}}
                                </td>
                                <td>
                                    {{if Address.Length >=2}}
                                    <input type="text" value="${Address[1].State}" style="width: 50px" />
                                    {{else}}
                                    <input type="text" value="" style="width: 50px" />
                                    {{/if}}
                                </td>
                                <td>
                                    {{if Address.Length >=3}}
                                    <input type="text" value="${Address[2].State}" style="width: 50px" />
                                    {{else}}
                                    <input type="text" value="" style="width: 50px" />
                                    {{/if}}
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
        </table>

Here is the Json as well:

{
    "Name": "Peter",
    "EmpId": "10",
    "Employer": [
        {
            "EmpName": "ABC",
            "EmpCity": "Jal",
            "Address": [
                {
                    "State": "MO",
                    "City": "St.Louis" 
                } 
            ] 
        } 
    ]
}
1

There are 1 answers

4
Luke On BEST ANSWER

use an empty object {address:[]}

$("#empTemplate").tmpl({address:[]}).appendTo("#divEmp");