0

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.

2
  • Are you trying to get a subset of ITEMS[0].FILTER using a function for the each template? Commented Mar 23, 2011 at 21:51
  • i'm trying to iterate across each item in the FILTER array. Is that not how you do it? Commented Mar 23, 2011 at 22:04

1 Answer 1

2

Ah, figured out the syntax :

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

Simple actually :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.