2014-02-28 40 views
0

我有這樣的代碼:如何在鈦android listView中添加嵌套的childTemplates?

var listViewRowTemplate = { 
     properties: { 
      height: '100dp' 
     }, 
     childTemplates: [ 
      { 
       //lblIndicator 
       type: 'Ti.UI.Label', 
       bindId:'lblIndicator', 
       properties: {} 
      }, 
      { 
       //lblCustomer 
       type: 'Ti.UI.Label', 
       bindId:'lblCustomer', 
       properties: {} 
      }, 
      { 
       //menu View 
       type: 'Ti.UI.View', 
       bindId:'menuView', 
       properties: {}, 
       childTemplates: [ 
        { 
         //lblName 
         type: 'Ti.UI.Label', 
         bindId:'lblName', 
         properties: {} 
        } 
       ] 
      } 
     ] 
    }; 

    var section = Ti.UI.createListSection({}); 
    var listView = Ti.UI.createListView({ 
     top:'175dp', 
     height:Ti.UI.FILL, 
     templates: { 'listViewRowTemplate': listViewRowTemplate }, 
     sections: [ section ] 
    }); 

,我填補的ListView使用此代碼:

var listViewRow; 


     listViewRow = { 
      template:'listViewRowTemplate', 
      properties:{backgroundColor:'green'}, 
      _data:myData, 
      lblIndicator:_globals.get('combine')(_styles.get('label.normal'), { 
       _id:'indicator', 
       left:'10dp', 
       backgroundImage:bgIndicator, 
       backgroundSelectedImage:bgIndicatorHover, 
       height:'40dp', 
       width:'40dp', 
       top:'5dp' 
      }), 
      lblCustomer:_globals.get('combine')(_styles.get('label.normal'), { 
       _id:'customer', 
       text:myData[i].CustomerShortDesc, 
       left:'50dp', 
       top:'0dp', 
       height:'50dp' 
      }), 
      menuView:_globals.get('combine')(_styles.get('view.tableview.header'), { 
       _id:'menu', 
       left:'10dp', 
       height:'40dp', 
       width:_globals.get('app.platformWidth') * 0.7, 
       top:'50dp', 
       lblName:_globals.get('combine')(_styles.get('label.normal'), { 
        _id:'name', 
        left:'10dp', 
        text:'This is for name', 
        color:'red', 
        height:'40dp', 
        width:'40dp', 
        top:'5dp' 
       }) 
      }) 
     }; 

     listViewData.push(listViewRow); 

     section.setItems(listViewData); 

您的信息,_globals.get()_styles.get()是我自己的自定義JS文件返回屬性或對象。

我可以看到我喜歡lblIndicator,lblCustomer和menuView其他成分,但不是我的嵌套的組件(lblName)..

有誰知道如何填寫列表視圖與嵌套組件(內childTemplates childTemplates)?

請給我一些建議。許多感謝..

回答

0

我找到了解決辦法.. 這裏的工作代碼:

var listViewRow; 


     listViewRow = { 
      template:'listViewRowTemplate', 
      properties:{backgroundColor:'green'}, 
      _data:myData, 
      lblIndicator:_globals.get('combine')(_styles.get('label.normal'), { 
       _id:'indicator', 
       left:'10dp', 
       backgroundImage:bgIndicator, 
       backgroundSelectedImage:bgIndicatorHover, 
       height:'40dp', 
       width:'40dp', 
       top:'5dp' 
      }), 
      lblCustomer:_globals.get('combine')(_styles.get('label.normal'), { 
       _id:'customer', 
       text:myData[i].CustomerShortDesc, 
       left:'50dp', 
       top:'0dp', 
       height:'50dp' 
      }), 
      menuView:_globals.get('combine')(_styles.get('view.tableview.header'), { 
       _id:'menu', 
       left:'10dp', 
       height:'40dp', 
       width:_globals.get('app.platformWidth') * 0.7, 
       top:'50dp' 
      }), 
      lblName:_globals.get('combine')(_styles.get('label.normal'), { 
       _id:'name', 
       left:'10dp', 
       text:'This is for name', 
       color:'red', 
       height:'40dp', 
       width:'40dp', 
       top:'5dp' 
      }) 
     }; 

     listViewData.push(listViewRow); 

     section.setItems(listViewData); 

非常感謝..希望它有助於..

相關問題