反应本地动态运行时ui创建
答
我根据我从服务器获取的类型属性在屏幕上呈现不同的UI控件。 我使用的ListView如下
<ListView
enableEmptySections = {true}
style={{flex:1}}
dataSource={ds.cloneWithRows(data)}
renderRow=
{
(data, secId, rowId, rowMap) =>
{
return this.renderRow(data, secId, rowId, rowMap);
}
}
/>
,我从服务器得到的数据是按以下格式
[{类型: '文本',标签: 'LABEL1'},{类型:“复选框',label:'label2'}];
在renderRow方法,根据数据类型我呈现不同的UI控件
renderRow(data, secId, rowId, rowMap) {
if (data.type=='Text')
{
var contentRow = <TextInput style={styles.InputRowBox} />;
return (contentRow);
}
else if (data.type=='CheckBox')
{
var notificationRow = <CheckBox style={styles.checkboxStyle} />
return (notificationRow);
}
}
注:CheckBox控件来工作,你将需要添加复选框包,我从这个link
添加