【问题标题】:JSRender how to access variable outside the blockJSRender如何访问块外的变量
【发布时间】:2012-10-11 08:08:26
【问题描述】:

我正在使用 jsrender 来显示我的 json 对象的详细信息。 我想知道如何访问列表中的外部变量。 谢谢。

   <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>

【问题讨论】:

    标签: javascript jquery json jsrender


    【解决方案1】:

    据我了解,这是您的示例: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>
    

    【讨论】:

    • {{#each}} 而不是 {{for}}.. 它适用于新的 jsrender.. 但我怎样才能使用旧的 jsrender 使其工作
    • 在旧的 jsrender 中这个等价物是什么? --> {{>#parent.parent.data.theater}}
    • @newbie 我使用新的 JSRender,你能用你的版本创建 jsfiddle.net 示例吗?
    • 我认为标签应该不同..你知道这个标签在旧的 jsrender 版本中的等价物是什么吗.. {{>#parent.parent.data.theater}跨度>
    • 我们的jsrender版本是“v1.0pre”
    猜你喜欢
    • 2015-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-08
    • 2021-01-01
    • 2018-10-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多