我想设置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}]

展开全部
收起
1回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
  • Julian

    11人对此回答表示赞同

    我是2.1.1的微信版本,使用官方的例子也是默认值没有生效,不知道是不是官方的bug

    展开
    11
    0回复
    发布于 6年前

    评论(0)

    收起评论

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部