【问题标题】:Proper way to access a object property in a jquery-tmpl {{each}} statement在 jquery-tmpl {{each}} 语句中访问对象属性的正确方法
【发布时间】:2011-04-24 12:36:30
【问题描述】:

我正在使用jquery-tmpl。我的对象模型很简单——SalesProspect,它包含SalesProspectAction 对象的集合。这两个对象都有一个名为 Status 的字段。如何在each 循环中获取孩子的状态?它总是拉着父母的。

<script id="tmplActions" type="text/x-jquery-tmpl">
    <p>${GuestName}</p>
    <table class="stdtable" cellpadding="3" cellspacing="0" width="100%">
        <thead><tr><td>Date</td><td>By</td><td>Changed To</td><td>Notes</td></tr></thead>
        <tbody>
            {{each(i,action) SalesProspectActions}}
            <tr>
                <td>${DateCreated}</td>
                <td>${CreatedBy}</td>
                <td>${Status}</td>
                <td>${Notes}</td>
            </tr>
        {{/each}}
        </tbody>
    </table>
</script>

我尝试了一些不同的方法,例如{$action.Status} 等,但都没有成功。

【问题讨论】:

  • 我知道您想尝试,但由于您的示例不正确,我想确保...您使用了${action.Status},但它不起作用(不是$ 的位置)?
  • Doh,真不敢相信我错过了——你是对的。随意添加它作为答案。

标签: jquery jquery-templates


【解决方案1】:

正如我在评论中指出的(尽管有错别字...),语法是 ${action.Status} 而不是 {$action.Status}

【讨论】:

    【解决方案2】:

    你确定这段代码不起作用吗?

    {{each(i,action) SalesProspectActions}}
        <tr>
            <td>${action.Status}</td>
        </tr>
    {{/each}}
    

    【讨论】:

      【解决方案3】:

      object 可以作为模板选项传递。这是我在项目中所做的:

      http://codekiku.blogspot.in/2012/04/jquery-template-options-pass-objects-or.html

      【讨论】:

        猜你喜欢
        • 2016-06-04
        • 2011-07-11
        • 2014-01-21
        • 1970-01-01
        • 2017-05-10
        • 1970-01-01
        • 1970-01-01
        • 2012-01-13
        • 1970-01-01
        相关资源
        最近更新 更多