我正在使用可跟踪的变量,我将搜索该值但是设置数据时出错我已搜索出出现此错误但找不到的原因。
class TurListesiStore {
@observable list = [];
@action async getTurList() {
this.loading = true;
try {
const { data } = await axios..
runInAction(() => {
let listx = data.KusTurleriListesi;
let list = [];
for (let i = 0; i < listx.length; i++) {
let y = { data: listx[i].TurListesi, title: listx[i].TurAile };
list.push(y);
}
this.list =list;
this.loading = false;
});
}
}
此处是屏幕代码
const { TurListesiStore } = this.props;
<SectionList
keyExtractor={(item, index) => item.id}
renderItem={({ item, index }) => {
return (
<SectionListItem
item={item}
index={index}
></SectionListItem>
);
}}
renderSectionHeader={({ section }) => {
return <SectionHeader section={section} />;
}}
sections={TurListesiStore.list}
/>
尝试:
let list = [];
for (let idx in listx) {
list.push({ data: listx[idx].TurListesi, title: listx[idx].TurAile });
}
在javascript数组中,不一定在所有索引上都填充
var myArray = [0,1,2,3]
console.log(' 1) myArray.length', myArray.length ) // --> 4
myArray[6] = 6
console.log(' 2) myArray.length', myArray.length ) // --> 7
console.log(' 2) Object.keys(myArray).length', Object.keys(myArray).length ) // --> 5
myArray[-4] = 99
console.log(' 3) myArray.length', myArray.length ) // --> 7 again
console.log(' 3) Object.keys(myArray).length', Object.keys(myArray).length ) // --> 6
Object.keys(myArray).length
console.log(' myArray[-4]', myArray[-4] ) // --> 99
let r1 = ''
for(let i=0;i<myArray.length; i++) {
r1 += ' '+i+'->'+myArray[i]
}
console.log(r1 ) // 0->0 1->1 2->2 3->3 4->undefined 5->undefined 6->6
let r2 = ''
for(let idx in myArray) {
r2 += ' '+idx+'->'+myArray[idx]
}
console.log(r2 ) // 0->0 1->1 2->2 3->3 6->6 -4->99
.as-console {background-color:black !important; color:lime;}
.as-console-wrapper {min-height:100% !important; top:0;}