发表于: 2020-06-04 20:39:51
1 2280
今天完成的事情:
1.推进任务
明天计划的事情:
1.推进任务
遇到的问题和收获:
<view class="title">试试什么职业最适合你</view>
<view class="section" wx:for="{{objArray}}" wx:for-index="idx" wx:for-item="itm" wx:key="idx">
<picker bindchange="bindPickerChange" value="{{itm.index}}" data-content="{{itm.options[itm.index]}}"
data-current="{{idx}}" range="{{itm.options}}" class="sel">
<view class="picker">
{{itm.title}}:{{itm.options[itm.index]}}
</view>
</picker>
</view>
<button type="primary" bind:tap="handleChoose">选好了,点击查看</button>
使用picker的基本效果。
data: {
objArray: [{
index: 3,
title: '学历',
options: ['初中以下', '高中', '大专', '本科', '博士']
},
{
index: 0,
title: '性别',
options: ['男', '女']
},
{
index: 1,
title: '年龄',
options: ['18岁以下', '18-24岁', '25-30岁', '30岁以上']
},
{
index: 0,
title: '特长',
options: ['无特长', '绘画基础', '网络相关', '原型设计', '文字功底']
},
{
index: 1,
title: '逻辑',
options: ['渣渣', '普通', '卓越']
}],
遍历的数据从数组中获取。
bindPickerChange: function (e) {
console.log(e)
console.log('picker发送选择改变,携带值为', e.detail.value)
// 定义一个变量currentIndex 储存触发事件的数组对象的下标
const currentIndex = e.target.dataset.current
//根据下标 改变该数组对象中的index值
this.data.objArray[currentIndex].index = e.detail.value
//把改变某个数组对象index值之后的全新objArray重新 赋值给objArray
this.setData({
objArray: this.data.objArray
// 'recommendData.education':this.data.objArray[currentIndex].
})
},
目前就是一个修改数据的问题还不太懂。
一种是不修改数据,默认就直接点击提交。
一种就是更改选项后再提交。如何修改了数据时候,把修改的数据传出去。
评论