2011-11-18 66 views
0

我是Sencha Touch的新手,嘗試使用Sencha Touch版本2進行xtemplates演示。這是我的代碼。在Sencha Touch 2將數據綁定到tpl,面板不起作用

Ext.application({ 
    name: 'Templates', 

    launch: function(){ 
    var content, planetInfo, planetEarth; 

    planetEarth = { name: "Earth", mass: 1.00 }; 

    planetInfo = new Ext.XTemplate(
     "<h2>{name}</h2>mass: {mass}" 
    ); 

    content = new Ext.Panel({ 
     fullscreen: true, 
     scroll: 'vertical', 
     tpl: planetInfo 
    }); 

    content.update(planetEarth); 
    } 
}); 

此代碼的輸出應該是面板中的HTML格式。但我只是得到[object Object]。請幫忙。

回答

3

請勿使用content.update(planetEarth)方法,因爲它已在sencha-touch-2中棄用。

這裏是正確的代碼的一個例子:

Ext.application({ 
     name: 'Templates', 

     launch: function() { 
      var content, planetInfo, planetEarth; 

      planetEarth = { name: "Earth", mass: 1.00 }; 

      planetInfo = new Ext.XTemplate(
       "<h2>{name}</h2>mass: {mass}" 
      ); 

      content = Ext.create("Ext.Panel", { 
       fullscreen: true, 
       scroll: 'vertical', 
       tpl: planetInfo, 
       data: planetEarth 
      }); 
     } 
    }); 
+0

沒錯。我試圖找出如何對數據進行更改,然後重新繪製模板。我找不到面板(或祖先)的刷新/重繪/更新方法。 –

1

要更新顯示值(煎茶觸摸2),用 「setRecord(用新的模型實例)」。

me.getSomeComponentWithTpl().setRecord(someModelInstance); 
相關問題