我有这样的代码:
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)..
有没有人知道如何用嵌套组件填充listview(childTemplates中的childTemplates)?
请给我一些建议..非常感谢..
答案 0 :(得分: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);
非常感谢..希望它有所帮助..