私はrealm dbと反応ネイティブを使用しています。次のようにレルムスキーマは次のとおりです。セクションのヘッダーでレルムリストビューをレンダリングする方法
static schema = {
name: 'TodoItem',
primaryKey: 'id',
properties: {
id: {type: 'string'},
value: {type: 'string'},
Category: {type: 'string'},
completed: {type: 'bool', default: false},
createdTimestamp: {type: 'date'}
}
}
export const todoItemDS = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2, sectionHeaderHasChanged: (s1, s2) => s1 !== s2})
const mapStateToProps = (state, props) => ({
dataSource: todoItemDS.cloneWithRowsAndSections(todoItemsResults),
}
次のようにListViewのタグは次のとおりです。
<ListView
dataSource={dataSource}
renderRow={this.renderRow.bind(this)}
renderSectionHeader={this.renderSectionHeader.bind(this)}
/>
とrenderSectionHeader:
renderSectionHeader(sectionData, category) {
return (
<Text>{category}</Text>
)
}
renderRow(item){
const {dataSource, deleteTodoItem} = this.props
return (
<View style={{ justifyContent: 'space-between',flexDirection: 'row'}}>
<CheckBox onPress={(e) => this.completed(item.id,item.value,e.target.checked)} style={{marginTop: 15 }}checked={item.completed} />
<Text onPress={(e) => this.goToPageTwo(item.id)} style={{ alignSelf: 'center',flex:10}} >{item.value}
</Text>
<Button iconLeft large transparent primary style={{ height: 30 , flex:1 }} onPress={() => deleteTodoItem(item)}>
<Icon name="trash-o" style={{ color: 'red' }} />
</Button>
</View>)
}
私は、この関数からデータソースtodoItems埋める:
export const getTodoItems =() => {
const todoItems = TodoItem.get().sorted('createdTimestamp', true);
return todoItems
}
を
ただし、行とセクションは、イメージに示されているように、空のセクションのテキストと空の行のテキストでレンダリングされます。このコードに欠けている何
とどのように私は正しくセクションと行をレンダリングすることができますか?
Iは次のようにデータソースを満たす領域コードにリスナーを追加した:しかし、私は、追加された項目を見ることができない
export const getTodoItems =() => {
console.log('create db:', Realm.path)
const itemData = {}
const todoItems = TodoItem.get().sorted('createdTimestamp', true).filtered('completed=false');
todoItems.addListener((items, changes) => {
// Update UI in response to inserted objects
changes.insertions.forEach((index) => {
if(itemData[items[index].Category]) {
itemData[items[index].Category].push(items[index])
} else
itemData[items[index].Category] = []//;
});
// Update UI in response to modified objects
changes.modifications.forEach((index) => {
});
// Update UI in response to deleted objects
changes.deletions.forEach((index) => {
// Deleted objects cannot be accessed directly
// Support for accessing deleted objects coming soon...
});
});;
todoItems.forEach((item) => {
if(itemData[item.Category]) {
itemData[item.Category].push(item)
} else
itemData[item.Category] = []//;
})
return itemData //todoItems
}
。追加されたアイテムは、別のアイテムを追加した後にのみ表示されます。何か案は?
ような何かを行うことができますか? – dotcomXY
@dotcomXYデータソースを満たす関数を追加しました。 –
これで、同じ量の行が表示され、カテゴリ行の正しい量がレンダリングされ、その中のコンテンツだけがTextコンポーネントが空になりますか? – dotcomXY