我正在使用react-native-db-models节点模块。我的数据库模型上有3行。 => (title | privateid | action)
这次锻炼我失去了2天。我想列出数据库中的所有记录。怎么了?
var Download = React.createClass({
getInitialState: function () {
return {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
})
};
},
componentDidMount: function() {
this.fetchData();
},
fetchData: function () {
DB.downloads.get_all(function(result) {
var data = [];
for(var i = 1; i <= result.totalrows; i++) {
console.log(result.rows[i]);
data[i-1] = result.rows[i];
this.setState({
dataSource: dataSource.cloneWithRows(result.rows[i]),
loaded:false,
})
}
});
},
render: function () {
return (
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderTrack}
style={styles.listView}/>
);
},
renderTrack: function (track) {
return (
<View>
<Text>{track.title}</Text>
</View>
);
}
});
答案 0 :(得分:0)
这样做......
fetchData: function () {
DB.downloads.get_all(function(result) {
var data = [];
for(var i = 1; i <= result.totalrows; i++) {
data.push(result.rows[i]);
}
// Outside of the loop, apply the data
this.setState({
dataSource: dataSource.cloneWithRows(data),
loaded:false,
})
});
},