问题模块 |
---|
API和组件 |
Hi All,
我在Data 里面定议了:
persons:[{My_Names:'',WX_Pics:'',My_Enroll_Years:'',My_Majors:'',My_Business:'',My_Phones:''}]
但在一下wx.request 的success里面对返回的字符串进行解释后,想对persons进行循环赋值。
在一个For的语句里写:
persons[i].My_Names = My_Name_temp;
报如下的错。
thirdScriptError
Cannot set property 'My_Names' of undefined;at api request success callback function
TypeError: Cannot set property 'My_Names' of undefined
试着改成:
persons[0].My_Names = My_Name_temp;就没有报错。但循环语句不能直接写成这样0,1,2......
如何搞?
网友回复
一楼正解!
有道理!我把{}里面的东西重复了10次,就没这报错了!
但这样定义data,好像有点怪怪的。有没有简洁的写法。
persons:[{My_Names:'',WX_Pics:'',My_Enroll_Years:'',My_Majors:'',My_Business:'',My_Phones:''},{My_Names:'',WX_Pics:'',My_Enroll_Years:'',My_Majors:'',My_Business:'',My_Phones:''},{My_Names:'',WX_Pics:'',My_Enroll_Years:'',My_Majors:'',My_Business:'',My_Phones:''},{My_Names:'',WX_Pics:'',My_Enroll_Years:'',My_Majors:'',My_Business:'',My_Phones:''},{My_Names:'',WX_Pics:'',My_Enroll_Years:'',My_Majors:'',My_Business:'',My_Phones:''},{My_Names:'',WX_Pics:'',My_Enroll_Years:'',My_Majors:'',My_Business:'',My_Phones:''},{My_Names:'',WX_Pics:'',My_Enroll_Years:'',My_Majors:'',My_Business:'',My_Phones:''},{My_Names:'',WX_Pics:'',My_Enroll_Years:'',My_Majors:'',My_Business:'',My_Phones:''},{My_Names:'',WX_Pics:'',My_Enroll_Years:'',My_Majors:'',My_Business:'',My_Phones:''},{My_Names:'',WX_Pics:'',My_Enroll_Years:'',My_Majors:'',My_Business:'',My_Phones:''}],
醉了,你这数组长度就是1,还用for循环,persons[0]以外的当然都是null