Skip to content

Commit eddb35d

Browse files
author
mrarronz
committedJul 5, 2018
update code
fix bug
1 parent c9df14c commit eddb35d

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed
 

‎Chapter11-SQLiteStorage/SQLiteStorage/src/screen/HomeScreen.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ export default class HomeScreen extends React.Component {
7373
)}
7474
renderHiddenRow={ (data, secId, rowId, rowMap) => (
7575
<View style={styles.rowBack}>
76-
<Text>Left</Text>
7776
<TouchableOpacity style={[styles.backRightBtn, styles.backRightBtnLeft]} onPress={ () => this.closeRow(rowMap, `${secId}${rowId}`) }>
7877
<Text style={styles.backTextWhite}>Close</Text>
7978
</TouchableOpacity>
80-
<TouchableOpacity style={[styles.backRightBtn, styles.backRightBtnRight]} onPress={ () => this.deleteRow(rowMap, `${secId}${rowId}`) }>
79+
<TouchableOpacity style={[styles.backRightBtn, styles.backRightBtnRight]} onPress={ () => this.deleteRow(data, rowMap, `${secId}${rowId}`) }>
8180
<Text style={styles.backTextWhite}>Delete</Text>
8281
</TouchableOpacity>
8382
</View>
@@ -95,15 +94,24 @@ export default class HomeScreen extends React.Component {
9594
}
9695
}
9796

98-
deleteRow(rowMap, rowKey) {
97+
deleteRow(data, rowMap, rowKey) {
9998
this.closeRow(rowMap, rowKey);
100-
const newData = [...this.state.studentList];
101-
const prevIndex = this.state.studentList.findIndex(item => item.key === rowKey);
102-
let student = this.state.studentList[prevIndex + 1];
103-
console.log(student);
104-
DBManagerModule.deleteStudent(student.studentName);
105-
newData.splice(prevIndex, 1);
106-
this.setState({studentList: newData});
99+
DBManagerModule.deleteStudent(data.studentName);
100+
let index = -1;
101+
let tempList = this.state.studentList;
102+
for (let i = 0; i < tempList.length; i++) {
103+
let obj = tempList[i];
104+
if (obj.studentName === data.studentName) {
105+
index = i;
106+
break;
107+
}
108+
}
109+
if (index >= 0) {
110+
tempList.splice(index, 1);
111+
this.setState({
112+
studentList: tempList
113+
})
114+
}
107115
}
108116
}
109117

0 commit comments

Comments
 (0)
Please sign in to comment.