简体   繁体   English

如何从Realm中为我的ListView获取数据

[英]How to get Data from Realm for my ListView

I have a problem, in my first screen LaunchScreen , i have a button for adding some data in my Realm : 我有一个问题,在我的第一个屏幕LaunchScreen中 ,我有一个用于在Realm中添加一些数据的按钮:

addBdd(realm){
 realm.write(() => {
  realm.create('Bills', {
    type: "Fournitures",
    creditor: "Entreprise A",
    month: "Avril",
    year: "2017",
    price: "40",
  })
});
 alert("Count : " + realm.objects('Bills').length);
}

All is working this far. 到目前为止,所有人都在工作。 But after that, i have two views, a LoginScreen , and the View where data must be applied to my list view : ListBillScreen 但是在那之后,我有两个视图,一个LoginScreen和一个必须将数据应用于我的列表视图的视图: ListBillScreen

<ListView
    enableEmptySections={true}
    style={styles.listView}
    dataSource={this.state.dataSource}
    renderRow={(data) => <Row {...data} navigator={this.props.navigator} />}
    renderSeparator={(sectionId, rowId) => <View key={rowId} style={styles.separator} />}
  />

Which calls a class named Row : 哪个调用名为Row的类:

function goBillscreen() {
props.navigator.push({ screen: 'BillScreen', props: {
billType : props.type,
billCreditor : props.creditor,
billMonth : props.month,
billYear: props.year,
billPrice: props.price
}});
}

return(
<TouchableHighlight onPress={() => goBillscreen()}>
<View style={styles.container}>
<Image source={{ uri: props.picture}} style={styles.photo} />
<Text style={styles.text}>
  {`${props.type} ${props.creditor} / ${props.month} ${props.year}`}
  {`\n${props.price} euros`}
</Text>
</View>
</TouchableHighlight>
);

The question is : How do I give my realm to the ListBillView to give the data like : 问题是:如何将我的领域提供给ListBillView以提供类似的数据:

this.state = {
  dataSource: ds.cloneWithRows(datafromrealm)
};

and how can I give type, creditor, month, year and price to Row ? 以及如何给Row提供类型,债权人,月份,年份和价格?

Sorry for the long post I tried but I'm lost ! 对不起,我尝试了很长时间,但我迷路了!

Thanks for all ! 谢谢大家!

the question is not well defined but seems you are asking how to process data for every row in your listview. 这个问题的定义不明确,但似乎您在询问如何处理列表视图中每一行的数据。 You can check some of the examples we have in realm-js repo like this one 您可以检查一些在realm-js存储库中的示例,例如:

https://github.com/realm/realm-js/blob/master/examples/ReactExample/components/todo-listview.js#L85 https://github.com/realm/realm-js/blob/master/examples/ReactExample/components/todo-listview.js#L85

This is a todo list sample application which uses a ListView to show the todo items. 这是一个待办事项列表示例应用程序,它使用ListView显示待办事项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用领域数据制作带有列表视图的android应用? - how to make android app with listview using data from realm? 如何在我的Listview中添加onItemClick以使用Asynctask从MYSQL获取数据 - how to add onItemClick in my Listview that get data from MYSQL with Asynctask 如何从数据库中获取数据并将其放在可单击的ListView上? - How to get data from my database and put it on a ListView that is clickable? 如何在领域数据库中查看listview中的查询数据? - How to view the queried data in listview in realm database? 是否可以从onclick的列表视图中获取数据 - Is it possible to get data from my listview onclick 如何使用**日期对象**从**领域数据库**获取数据? - How to get data from **Realm database** using **date object**? 如何从Realm读取数据 - How to read data from Realm 滚动到列表视图的顶部:如何从适配器获取列表视图? - Scroll to top on the listview : How to get listview from my adapter? 如何从数据库的listView中的选定项中获取数据并在alertdialog上查看? - how I can get the data from the selected item in the listView from my database and view it on alertdialog? 如何从JSONobject获取数据并将其显示在列表视图中? - How to get data from JSONobject and display it into a listview?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM