我正在使用这个 - > https://github.com/jquery/jquery-tmpl
我需要的是递归地使用所述插件显示一个对象数组。
为什么这不起作用? - > {{if value.exists != false}} checked {{/if}}
请考虑以下代码:
{{each list}}
<li><label class="checkbox{{if value.exists != false}} active{{/if}}"><input type="checkbox" {{if value.exists != false}} checked{{/if}} disabled>${$value.type}</label></li>
{{/each}}
对象:
{ "list":
[
{ type: "GRAPH_A", exists: true },
{ type: "GRAPH_B", exists: false },
{ type: "GRAPH_C", exists: false },
]
}
这是我得到的错误:
ReferenceError:未定义值源文件: 应用程序/脚本/ jquery.tmpl.min.js
行:10
答案 0 :(得分:0)
试试这个演示......看看源代码是否有用。 Using {{if}} and {{else}}
数据:
var movies = [{
Title: "Meet Joe Black",
Languages: "English and French",
Subtitles: "English"
}, {
Title: "Eyes Wide Shut",
Subtitles: "French and Spanish"
}, {
Title: "The Mighty"
}
];
HTML:
<script id="movieTemplate" type="text/x-jquery-tmpl">
<tr>
<td>${Title}</td>
<td>
{{if Languages}}
Alternative languages: <em>${Languages}</em>.
{{else Subtitles}}
Original language only... <br/>Subtitles in <em>${Subtitles}</em>.
{{else}}
Original version only, without subtitles.
{{/if}}
</td>
</tr>
</script>
答案 1 :(得分:0)
尝试
{{each list}}
<li><label class="checkbox{{if exists != false}} active{{/if}}"><input type="checkbox" {{if exists != false}} checked{{/if}} disabled>${type}</label></li>
{{/each}}
演示:Fiddle