jQuery Tmpl值与属性不工作

jQuery Tmpl Value with Property not working

本文关键字:工作 属性 Tmpl jQuery      更新时间:2023-09-26

我正在使用这个-> 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: value is not defined应用程序/脚本/jquery.tmpl.min.js

线:10

Try

{{each list}}
    <li><label class="checkbox{{if exists != false}} active{{/if}}"><input type="checkbox" {{if exists != false}} checked{{/if}} disabled>${type}</label></li>
{{/each}}

演示:小提琴

试试这个演示…看源代码可能会有用。使用{{if}}和{{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>