1
我在jquery中有一個模板,並試圖只顯示沒有數據的HTML。我試圖綁定'null'而不是json「data」,但它給出了錯誤(Address is undefined)。以下是代碼聲明。沒有數據的jquery顯示模板
$("#empTemplate").tmpl(null).appendTo("#divEmp");
HTML標記:
<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>
這裏是JSON作爲得好:
{
"Name": "Peter",
"EmpId": "10",
"Employer": [
{
"EmpName": "ABC",
"EmpCity": "Jal",
"Address": [
{
"State": "MO",
"City": "St.Louis"
}
]
}
]
}
你在哪裏打算爲`Address`被引用? – 2011-02-02 17:13:29
Address是一個數組,它是Employee對象的一部分 – user583126 2011-02-02 17:19:59