本文介绍了在 ExtJS XTemplate 中调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉使用函数来确定使用 xtemplate 的特定条件,但不确定如何在没有条件 if 语句的情况下直接调用函数.

I'm familiar with using a function to determine a specific condition using xtemplate but not sure how to directly call a function without the conditional if statement.

例如,我的代码想要将一些字符附加到我在 xtemplate 中使用的字符串中.我认为最好的方法是在呈现 xtemplate 时附加字符.

My code, for example, wants to append some characters to a string that I am using within my xtemplate. I think the best way to do it is append the characters when the xtemplate is rendered.

var myTpl = new Ext.XTemplate(
  '<tpl for=".">',

    '<tpl if="this.isThumbnailed(thumbnailed) == true">',

      '<img src=this.getThumbUrl(rawThumbUrl)/>', //this call to function does not work, also tried variations of this.

    '</tpl>',

  '</tpl>',

 {
  isThumbnailed : function(thumbnailed) {
    return ...;
  },
  getThumbUrl : function(rawThumbUrl) {
    //... //this function does not get called.
    return ...;
  }

 }
)

推荐答案

查看XTemplate 构造函数 API 文档.那里有很多很好的例子.引用:

Have a look at the XTemplate constructor API docs. There are lots of good examples there. Quoting:

{[ ... ]} 之间的任何内容都被认为是在模板范围内执行的代码.

因此您应该能够执行以下操作:

So you should be able to do something like:

'<img src={[this.getThumbUrl(rawThumbUrl)]} />',

这篇关于在 ExtJS XTemplate 中调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 21:56