收藏
回答

如何在js文件中获取数组中对应下标的对象

问题模块
API和组件

data中的数组

requests:[{requestTitle:'1.你是一丝不苟的人?',nextYesRequest:2,nextNoRequest:5},

    {requestTitle:'2.你的想法比一般人较悲观?',nextYesRequest:6,nextNoRequest:3},

    {requestTitle:'3.常有人来找你商量事情?',nextYesRequest:7,nextNoRequest:4},

    {requestTitle:'4.你很爱吃醋?',nextYesRequest:8,nextNoRequest:6},

    {requestTitle:'5.你给人的第一印象通常很好?',nextYesRequest:9,nextNoRequest:6},

    {requestTitle:'6.曾经被家人说很好色?',nextYesRequest:7,nextNoRequest:10},

    {requestTitle:'7.你恋爱时会忘了一切的存在?',nextYesRequest:10,nextNoRequest:11},

    {requestTitle:'8.你即使在人前放屁也会笑嘻嘻带过?',nextYesRequest:11,nextNoRequest:12},

    {requestTitle:'9.你是一个很好的倾听者?',nextYesRequest:14,nextNoRequest:13},

    {requestTitle:'10.你做人没原则?',nextYesRequest:9,nextNoRequest:14},

    {requestTitle:'11.还是觉得在自己家里最舒服?',nextYesRequest:12,nextNoRequest:15},

    {requestTitle:'12.只要是自己做不到的事情就会很在意?',nextYesRequest:15,nextNoRequest:16},

    {requestTitle:'13.你是一个能言善道的人?',nextYesRequest:18,nextNoRequest:17},

    {requestTitle:'14.你很喜欢人云亦云?',nextYesRequest:18,nextNoRequest:17},

    {requestTitle:'15.你结婚会要求对方的学历、身高、家世?',nextYesRequest:17,nextNoRequest:16},

    {requestTitle:'16.曾经有人说你的个性冷酷无情?',nextYesRequest:19,nextNoRequest:20},

    {requestTitle:'17.早上起床有起床气?',nextYesRequest:21,nextNoRequest:22},

    {requestTitle:'18.你经常会用鼻子哼歌?',nextYesRequest:17,nextNoRequest:23},

    {requestTitle:'19.想到的事情若不说出来就会觉得不舒服?',nextYesRequest:23,nextNoRequest:24},

    {requestTitle:'20.喜欢洗碗,更胜于做菜?',nextYesRequest:19,nextNoRequest:24},

    {requestTitle:'21.喜欢新闻胜于连续剧?',nextYesRequest:25,nextNoRequest:26},

    {requestTitle:'22.你每天看电视都会看到半夜?',nextYesRequest:26,nextNoRequest:21},

    {requestTitle:'23.你经常纯逛街不买东西?',nextYesRequest:27,nextNoRequest:24},

    {requestTitle:'24.你会定期阅读八卦杂志?',nextYesRequest:28,nextNoRequest:26},

    {requestTitle:'25.你每天都要睡午觉?',nextYesRequest:26,nextNoRequest:29},

    {requestTitle:'26.你很喜欢小孩子?',nextYesRequest:31,nextNoRequest:30},

    {requestTitle:'27.你有打算念大学甚至出国深造?',nextYesRequest:32,nextNoRequest:31},

    {requestTitle:'28.你会先听别人的意见,然后再陈述自己的想法?',nextYesRequest:33,nextNoRequest:27},

    ],//29-33代表A/B/C/D/E


方法

getWifeResult: function (e) {

    var nextIndex = Number(e.detail.value.answer);

    // this.setData({

    //   clickBtn: true,formIf:false

    // });

    var requestList = this.data.requests;

    var request = requestList[nextIndex];

    console.log("下一题"+nextIndex);

    console.log("requestList"+requestList);

    console.log("request"+request);

    //  this.setData({

    //   nextRequest:request

    // });

    

  }


打印的日志信息

下一题5

tool_wife.js [sm]:53 requestList[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

tool_wife.js [sm]:54 request[object Object]


为什么我拿到的requests是object,我要怎样才能在js文件用下表获取这个数组的对应的元素



最后一次编辑于  2017-02-11  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏关注问题回答