2

私のコンボボックスには、次のようなものがあります。

displayTpl: Ext.create('Ext.XTemplate',
                                    '<tpl for=".">',
                                        '{Nome} ({Valor})', 
                                    '</tpl>')

コンボに事前に選択された値がない場合は、この「()」が表示されることを除いて、正常に機能します。

だから私は、値が空のときに次のようなものが何も表示されないテンプレートを作成しようとしました:

displayTpl: Ext.create('Ext.XTemplate',
                                    '<tpl for=".">',
                                        '<tpl if="this.isEmpty({Nome})">',
                                            '',
                                        '<tpl else>',
                                            '{Nome} ({Valor})',
                                        '</tpl>',
                                    '</tpl>',
                                    {
                                        isEmpty: function (value) {
                                            return value == '';
                                        }
                                    })

しかし、tplが評価されると「Expected:」というエラーメッセージが表示され続けます(extjs-all-debug)

compile: function (tpl) {
    var me = this,
        code = me.generate(tpl);

    return me.useEval ? me.evalTpl(code) : (new Function('Ext', code))(Ext);

これを行う方法についてのアイデアはありますか?

4

2 に答える 2

3

tplタグの式に{}は必要ありません。したがって、代わりにこのテンプレートを試してください。

'<tpl for=".">',
    '<tpl if="this.isEmpty(Nome)">',
        '',
    '<tpl else>',
        '{Nome} ({Valor})',
    '</tpl>',
'</tpl>'
于 2012-10-18T13:20:09.023 に答える
0

私はそれを解決しました:)

displayTpl: Ext.create('Ext.XTemplate',
            '<tpl for=".">',
                '<tpl if="Nome != \'\'">',
                    '{Nome} ({Valor})',
                '<tpl else>',
                    '',
                '</tpl>',
            '</tpl>'
        )

コンボに渡されている値がわからないように見えるので、空とは異なる場合は、必要な構造を返します。そうでない場合は、''を返します。

于 2012-10-18T14:01:56.740 に答える