我正在尝试在ListView中加载数据,正在SQLite浏览器中执行查询,它执行得很好,但是当我在应用程序中运行它时,它会显示此错误
我的代码是:
async componentDidMount() {
let email = await AsyncStorage.getItem('email');
let qApartments=`SELECT ee.title || ' ап.' || ea.apartment,price,monthly_fee,ea.contact_email,ea.contact_phone,ea.contact_person,ea.apartment,client_id,tt.from_date,tt.to_date FROM entrances_entrance as ee INNER JOIN tasks_schedule as te on ee.id = te.entrance_id INNER JOIN entrances_apartment as ea on ee.id=ea.entrance_id INNER JOIN auth_user as au on au.id = te.assignee_id INNER JOIN tasks_task as tt on au.id = tt.assignee_id WHERE username = '${email}'`;
let qTasks=`SELECT title,price from tasks_task as tt INNER JOIN auth_user as au on au.id = tt.assignee_id WHERE username = '${email}'` ;
this.fetchData(qApartments,'a');
this.fetchData(qTasks,'b');
}
fetchData(query,stateWhere) {
db.transaction((tx) => {
tx.executeSql(query
, errorCB, (tx, results) => {
var len = results.rows.length;
const rows = [];
if(len > 0) {
for (let index = 0; index < results.rows.length; index++) {
const element = results.rows.item(index);
rows.push(element);
}
if(stateWhere==='a')
this.setState({apartData: rows});
else if(stateWhere==='b')
this.setState({holderData:rows})
}
});
});
}
ListView中的加载部分如下所示:
render() {
return (
<View style={styles.container}>
<View style={styles.btnFrame}>
<TouchableOpacity
onPress={this.showAparts}
style={styles.btn_top}>
<Text style={this.topTxtStyle()}>Списък Обекти</Text>
<Text style={this.topTxtStyle()}>(Апартаменти)</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={this.showApartsHolders}
style={styles.btn_top2}
>
<Text style={this.topTxtStyleHolder()}>Списък Taxes</Text>
<Text style={this.topTxtStyleHolder()}>Taxes</Text>
</TouchableOpacity>
</View>
{this.state.isApart &&
<View>
<ListView
dataSource={this.state.dataSource}
renderSeparator={this.ListViewItemSeparatorLine}
renderRow={
(rowData) =>
<TouchableOpacity style={styles.row_item} onPress={this.gotoApart.bind(this, rowData)}>
<Image source={Images.home_red} style={{ width: 40, height: 40 }} />
<View style={styles.text_view}>
<Text style={styles.row_text} >{rowData.title}</Text>
</View>
</TouchableOpacity>
}
/>
</View>
}
{this.state.isHolder &&
<View>
<ListView
dataSource={this.state.dataSource}
renderSeparator={this.ListViewItemSeparatorLine}
renderRow={
(rowData) =>
<TouchableOpacity style={styles.row_item} onPress={this.gotoHolders.bind(this, rowData)}>
{/* <Image source={Images.home_red} style={{ width: 40, height: 40 }} /> */}
<View style={styles.text_view}>
<Text style={styles.row_text} >{rowData.title}</Text>
</View>
</TouchableOpacity>
}
/>
</View>
}
</View>
)
}
有人可以帮助我解决什么问题。我试图做“`SELECT ee.title ||'ап。” || ea.apartment as ttl”和“ {rowData.ttl}”,但错误始终显示。