【问题标题】:jquery tmpl function inside IF statementIF语句中的jquery tmpl函数
【发布时间】:2013-05-01 11:20:44
【问题描述】:

我有以下 tmpl

{{if (${this.getFileLimit()})}}
<div class="files_wrapper">
    <div class="add-files">Click to add items</div>
</div>
{{/if}}

还有 JS 代码:

$('.addFiles').html($("#template").tmpl(data,{
  getFileLimit: function(){
    if (Object.size(data.items) == 10)
        return false;
    else
        return true;
  }
}))

所以一般函数 ${this.getFileLimit()} 可以工作(它在屏幕上呈现文本),但没有运气将它添加到 IF 语句中,总是会出错。

Uncaught SyntaxError: Unexpected token { 

谁有和idia如何使用IF里面的函数?

【问题讨论】:

  • getFileLimit 定义在哪里?
  • 在tmpl调用中: .tmpl(data,{ getFileLimit: function(){ if (Object.size(data.items) == 10) return false; else return true; }

标签: javascript jquery jquery-templates


【解决方案1】:

应该是……

{{if this.getFileLimit()}}

jsFiddle.

还值得一提的是,jQuery Template 是一个死项目。如果这是一个新项目,你可能会做其他事情会更好。

【讨论】:

    猜你喜欢
    • 2013-03-05
    • 2013-06-18
    • 2017-05-10
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多