如何在sencha touch中动态填充列表视图数据

时间:2013-08-02 12:27:04

标签: javascript extjs extjs4 sencha-touch-2 sencha-touch-2.1

我想用下面的数组变量填充列表数据我已将此arrray设置为存储此处是数组内的记录类型列表

   var logbookEntryList = [];

  var aircraftMxLog = new AircraftMxLog(); //domian 

    aircraftMxLog.mxlogIdNum = mxLogIdNum;
    aircraftMxLog.entryDatetime = entryDatetime;
    aircraftMxLog.recordName = recordName;
    aircraftMxLog.recordSourceId = recordSourceId;

     logbookEntryList.push(aircraftMxLog);


   var mxRelease = new MxRelease();
   mxRelease.mxReleaseTypeId = mxReleaseTypeId;
    mxRelease.entryDatetime = entryDatetime;
    mxRelease.comments = comments;
    mxRelease.firstName = firstName;
    mxRelease.lastName = lastName;

     logbookEntryList.push(mxRelease);

    var flightLog = new FlightLog();
    flightLog.flightNumId = flightNumId;
    flightLog.arvStationId = arvStationId;
    flightLog.deptStationId = deptStationId;
    flightLog.outDate = outDate;
    flightLog.offDate = offDate;

    logbookEntryList.push(flightLog);

所以我会在我的数组中使用不同类型的数据,所以如何将其映射到我的模型以填充列表视图

我已经尝试通过每个函数迭代存储我能够在迭代中获取每个元素对象但是在动态迭代到列表时无法设置itemtpl

这是代码

       createViewFactory :function(){
      var manageAmlStore=Ext.getStore('ManageAMLStore');
      manageAmlStore.setData(logbookEntryList);
     // this.getManageAmlStore().setData(logbookEntryList);
      //
        console.log('manage Aml store size '+manageAmlStore.getCount());
      var manageAmlList=Ext.getCmp('manageAMlList')
        manageAmlStore.each(function(item, index, length){
        //console.info(item,length,index);
        console.log('item '+item+' index '+index+' length '+length)
        console.log('item size '+item.length)
        if(logbookEntryList[index] instanceof AircraftMxLog){
            manageAmlList.setItemTpl('AircraftMxLog'+index);
         } else if(logbookEntryList[index] instanceof MxRelease){
            manageAmlList.setItemTpl('MxRelease'+index);
            // manageAmlList.initComponent();
              //manageAmlList.render();
         }else if(logbookEntryList[index] instanceof  FlightLog){
            manageAmlList.setItemTpl('FlightLog'+index);
          }else if(logbookEntryList[index] instanceof  MxAction){
            manageAmlList.setItemTpl('MxAction'+index);
         }
        //Ext.getCmp('manageAMlList').setItemTpl('test'+id)
         //this.getManageAmlList().setItemTpl('test'+id);
       });
      manageAmlList.bindStore(manageAmlStore);

     }

1 个答案:

答案 0 :(得分:0)

系统问题在于您发送字符串而不是变量

'MxRelease'+ index是一个字符串,而不是您之前声明的变量。

要做类似的事情,你必须以这种方式创建一个对象

TEMPLATe = 
{    tplvar = 
     {
      mxrelease2 : 'your template',
     },
    'MxRelease2' : function(tplvar){return tplvar.mxrelease2;},
}

如果我没错,那就叫做dictionnaries(javascript)