开发者

Calling javascript functions in JQuery Template

Say I have the following javascript object hierarchy:

ITEMS is an array with one element in it, FILTER is an array with 3 items in it

description "churches 开发者_运维知识库with some restrictions"
    ITEMS   {...}
        [0] {...}
            FILTER  {...}
                [0] {...}
                    fieldName   "CATEGORY"
                    fieldValue  "society%20news,us%20news"
                    schemaName  "all"

                [1] {...}
                [2] {...}
                    fieldName   "EDUCEDPEOPLE"
                    fieldValue  "barack%20obama"
                    schemaName  "all"
maxResults  "10"
name    "Save3"
queryText   "churches"
schemaName  "all"
shareOwner  "myuser"

I have the following JQuery template

<script id="TestTemplate" type="text/x-jquery-tmpl">
        <div>
            <h1>Query</h1>
            <ul>
                <li>Name <span>${saveName}</span></li>
                <li>Text <span>${queryText}</span></li>
                <li>Owner <span>${shareOwner}</span></li>

                <ol>
                {{each ITEMS[0].FILTER}}
                    <li>
                        <ul>
                            <li>Field Name ${$value.fieldName}</li>
                            <li>Field Value ${$value.fieldValue}</li>
                        </ul>
                    </li>
                {{/each}}
                </ol>
            </ul>
        </div>
</script>

The template is built from JSON and parsed into the above hierarchy (trimmed down for brevity)

    <script type="text/javascript">
    var oJSON = JSON.parse(data);
    if (oJSON !=null)
    {
        var alQueries = oJSON.QUERIES.QUERY;
        if (alQueries !=null)
        {
            $('#TestTemplate').tmpl(alQueries).appendTo('#test');
        }
    }                        
    </script>

    <div id="test"></div>

The question is, how do you call a javascript function on the items inside of FILTER? I can't figure out the syntax.


Ah, figured out the syntax :

<li>Field Value ${unescape($value.fieldValue)}</li>

Simple actually :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜