【问题标题】:How to call jQuery function inside jquery tmpl?如何在 jquery tmpl 中调用 jQuery 函数?
【发布时间】:2013-08-02 17:27:09
【问题描述】:

这是我的代码:

<script id="quotes" type="text/x-jquery-tmpl">
    {{each(i,market) Markets}}
        <span style="margin-left:3px;">${market.Symbol}</span>&nbsp;
        <span class="lastPrice">${market.CurrentQuote.LastPrice}</span>&nbsp;
    {{/each}} 
</script>

我想要的是让 LastPrice 看起来像“3.00”。我尝试使用 jquery 的数字功能,但无法使其工作。例如,如果我这样做:

$.number(${market.CurrentQuote.LastPrice}, 2)

它显示 $.number(3, 2) 而不是 3.00。如果我这样做,

${number($market.CurrentQuote.LastPrice, 2)}

它什么也不返回。

【问题讨论】:

    标签: jquery templates numbers formatter


    【解决方案1】:
    ${ number(market.CurrentQuote.LastPrice, 2) }.
    

    阅读this article

    【讨论】:

    • 我不懂该链接中的语言。但是,根据我在那里读到的内容,您的答案应该有效。然而,当我测试它时,它什么也没显示。
    • 我用它玩了一点,它看起来模板不理解数字函数(来自 jquery.number.js),因为如果我做 ${number(3, 2) 我仍然什么也得不到)}。如果我使用它的 js 文件,该功能可以正常工作。所以,我想知道我是否错过了 tmpl 的参考?
    • 通过阅读另一篇相关帖子 (stackoverflow.com/questions/4732853/…),jquery tmpl 似乎不支持此功能。有人可以证实这一点吗?
    猜你喜欢
    • 2011-07-23
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 2011-04-14
    • 2013-11-09
    • 2011-08-02
    • 2011-04-15
    • 2012-03-30
    相关资源
    最近更新 更多