0

我正在使用这个-> 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:未定义值源文件:app/scripts/jquery.tmpl.min.js

线路:10

4

2 回答 2

0

试试这个演示......看看源代码可能有用。 使用 {{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>
于 2013-03-20T08:47:45.813 回答
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}}

演示:小提琴

于 2013-03-20T08:53:04.017 回答