我是2.1.1的微信版本,使用官方的例子也是默认值没有生效,不知道是不是官方的bug
picker-view设定默认选中无效我想设置picker-view选中第二个item,item从0开始,不过我设置了picker-view的value为[2]之后,发现还是没有选中,相关代码如下: ------------------------------------------------------------------------------wxml <picker-view indicator-style="height: 50px;" style="width: 100%; height: 420rpx;" bindchange="bindChangePlan" indicator-style="{{style}}" value="{{selectedPlanIndex}}"> <!--完成天数 --> <picker-view-column> <view wx:for="{{planList}}" style="line-height: 50px">{{item.levelName}}</view> </picker-view-column> </picker-view> ---------------------------------------------------------------------------------js var selectedPlanIndex = [2]; Page({ /** * 页面的初始数据 */ data: { style:'background-color:#BCD7FF;height:50px;opacity:0.6', scrollLeft: scrollLeft, numPerDay: numPerDay, planList: [], planConfig:null, day:day, selectedNum: selectedNum, selectedDay: selectedDay, selectedPlanIndex: selectedPlanIndex }, 另外我发现planList如果是纯数字数组,比如[2001,2002,2003],对value设置selectedPlanIndex=[2],就可以选中2003这个item。而我的planList里面存放的是一个自定义数组,是不是跟这个有关系呢。 planList的自定义数组内容如下: [{"levelName":"CET4","levelCodeValue":"1","wordCount":3873},{"levelName":"CET6","levelCodeValue":"2","wordCount":5488},{"levelName":"初高中","levelCodeValue":"3","wordCount":2520},{"levelName":"雅思红宝书","levelCodeValue":"4","wordCount":3593},{"levelName":"雅思807听力","levelCodeValue":"5","wordCount":0},{"levelName":"GRE","levelCodeValue":"6","wordCount":7527},{"levelName":"GMAT","levelCodeValue":"7","wordCount":2432},{"levelName":"TEM4","levelCodeValue":"8","wordCount":0},{"levelName":"TEM8","levelCodeValue":"9","wordCount":4111},{"levelName":"高中词汇","levelCodeValue":"10","wordCount":386},{"levelName":"TOEFL","levelCodeValue":"11","wordCount":3906},{"levelName":"IELTS","levelCodeValue":"12","wordCount":3956}]
2018-08-27