2013-07-29 76 views
0

即時通訊工具中的新手。 我想在面板中顯示一些信息。 我創建一個面板,當我重寫數據tpl「未捕獲TypeError:無法設置屬性'innerHTML'爲null」發生。Extjs4 MVC Xtemplate錯誤:無法設置屬性'innerHTML'爲空

代碼:

initComponent: function(){ 
     var me = this; 
     var data={ 
       name:'lux', 
       age:'22' 
      }; 
     var item=Ext.create('Ext.panel.Panel',{title:'title'}); 
     var tpl=new Ext.XTemplate(
      '<p>Name: {name}</p>', 
      '<p>Company: {age}</p>', 
      '<p>Location:</p>', 
      '<p>Kids: ' 
      ); 
     tpl.overwrite(item.body, data); 

     Ext.applyIf(me,{ 
      items:item 

     }); 
     me.callParent(arguments); 
    } 

回答

0

的問題是,該組件尚未呈現,這意味着body元件不存在。相反,你應該使用api:

initComponent: function() { 
    var item = new Ext.panel.Panel({ 
     title: 'title', 
     tpl: [ 
      '<p>Name: {name}</p>', 
      '<p>Company: {age}</p>', 
      '<p>Location:</p>' 
     ], 
     data: { 
      name: 'lux', 
      age: '22' 
     } 
    }); 

    this.items = item; 
    this.callParent(arguments); 
} 
相關問題