2012-07-24 29 views
0

我是所有Sencha Touch东西的新手,但直到现在,我对它的功能非常敬畏。有一个问题,我无法解决。Sencha Touch:XTemplate在DataView中不可见

我想使用Tpl(XTemplate)进行日历视图。这个想法是为每个约会创建一个div元素,我可以将它放在容器中来布置它们。不知何故,我无法获得数据视图的工作。

我把我的代码剥离到最低限度:一个包含DataView的面板。当我使用itemTpl时,一切正常。但是当我使用tpl(有或没有XTemplate)时,我什么都看不到。我检查了它是否仅仅是一个显示故障(从模板中搜索了XXX),但事实并非如此。

这是我的代码:

Ext.define('InfoApp.view.CalendarDay', { 
extend: 'Ext.Panel', 
xtype: 'calendarday', 
requires: [ 'InfoApp.store.sAppointments'], 
config: { 
    title: 'Dag', 
    layout: 'fit', 
     items: [ 
       { 
        xtype: 'dataview', 
        store: 'appointmentStore', 

        //itemTpl: [ 'XXX {day} {course}' ] --> Works 
        tpl: new Ext.XTemplate('<tpl for=".">XXX {day} {course}</tpl>')--> Doesn't Work... 
       }   
     ] 
} 
}); 

在此先感谢您的任何建议或改进!

回答

0

坦克@brink为您的答案。

我花了一两天,但这个工作对我来说:

// Load the store 
    var store = Ext.getStore('appointmentStore'); 

    // Get the current range of the store 
    var data = store.getRange(); 

    // Create a custom template 
    var tpl = new Ext.XTemplate(<tpl for=".">{day} {course}</tpl>); 

    // Loop through the data array 
    var showData = array(); 
    for(var i=0;i<data.length;i++){ 
     showData.push(data[i].data); 
    } 

    // Get the panel by ID and push the html template 
    var panel = Ext.getCmp('appointmentspanel'); 
    panel.updateHtml(tpl.applyTemplate(showData));  
0

假设ST2和ST1不

http://docs.sencha.com/touch/2-0/#!/api/Ext.Component-cfg-tpl和对第三方物流的评论:配置在该文档中,它出现使用远程存储时有一个错误。即使你的商店有数据。你可以使用itemTpl:new XTemplate()或itemTpl:XTemplate.from('someid'),或者你可以推迟指定,直到以后,抓住你的数据视图,并去dv.setItemTpl(新XTemplate())等。

相关问题