2
我如何计算在每一个jQuery的模板项目和应用,如果该变量计数项目的jQuery模板
像
<script id="inventorySummaryTmpl" type="text/x-jquery-tmpl">
<tr>
{{each response}}
{{if response.length === 2 }}
</tr><tr>
{{/if}}
<td><img src='${icon}'> ${title} </td>
{{/each}}
</tr>
这是一个加载的JavaScript JSON并与jquery.TMPL
var ip = window.location.hash;
var request = $.ajax({
type: 'GET',
url: 'ajax/dashboard/widgets/inventorySummary.xsp?ip='+ip.substring(1),
dataType: 'json'
});
request.done(function(data){
$("#inventorySummaryTmpl").tmpl(data).appendTo("#inventorySummaryContent");
});
request.fail(function(jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
console.log(textStatus)
});
而且JSON交互
{
"response": [
{
"icon": "workstation",
"nbItems": "38",
"title": "Workstations"
},
{
"icon": "server",
"nbItems": "2",
"title": "Servers"
}
]
}
如果有人有任何ideeas。
我将对其进行测试,让大家都知道。在大约2-3小时 – Ancyent
好吧所以我更新了主帖,我让你知道它不工作...你有完整的信息,所以你可以测试它。 – Ancyent
也许你可以通过解释你想要什么样的最终HTML输出来提供帮助。我很难理解你想要你的模板做什么。 – jackwanders