简体   繁体   中英

JSRender how to access variable outside the block

I am using a jsrender to show the details of my json object. I am wondering how I can access the outside variable inside the list. Thank you.

   <script id="itemTemplate" type="text/x-jQuery-tmpl">

            {{=outsideVariable}} //STRING
            <div id="receipt_list_container">
                {{#each receiptSummary.receipts}}  //LIST
                    {{=formattedMonth}}
                                //HOW CAN I ACCESS THE OUTSIDE THE VARIABLE
                {{/each}}
            </div>

    </script>

As I understand, this is your example: Example Scenario: Accessing parent data.

var model = {
    specialMessage: function(...) { ... },
    theater: "Rialto",
    movies: [ ... ]
}

{{for movies}}
    <tr>
        <td>'{{>title}}': showing at the '{{>#parent.parent.data.theater}}'</td>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM