2012-10-18 121 views
2

在我的組合框我有這樣的事情:煎茶組合DisplayTpl

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 == ''; 
             } 
            }) 

但我不斷收到「預期:」一個錯誤消息時,太平人壽評估(extjs-全部調試)

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

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

有關如何做到這一點的任何想法?

回答

0

我解決它:)

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

因爲我似乎無法理解我的身影被傳遞到組合什麼價值,如果它是不同於空然後回到我想要的結構,如果沒有則返回「」

3

您不需要tpl標記中的表達式{}。因此,嘗試這個模板來代替:

'<tpl for=".">', 
    '<tpl if="this.isEmpty(Nome)">', 
     '', 
    '<tpl else>', 
     '{Nome} ({Valor})', 
    '</tpl>', 
'</tpl>' 
+0

我已經試過這已經雖然它從顯示出來:) –

+0

@MiguelTeixeira這是相當神祕然後停止錯誤它不會做什麼...。據我所知,這應該是正確的模板。你有沒有嘗試在isEmpty函數中放置一個console.log來驗證它是否被調用,以及傳遞給它的是什麼?這就是我從這一點開始的地方。 – Telgin

+0

甚至沒有叫... –