小程序
小游戏
企业微信
微信支付
扫描小程序码分享
如何点击增加取件,然后追加底下2个select
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
按你的要求,我可能会这样子处理
let list = []; //点击添加 add:(){ let item = {express :'',address:''}; list.push(item); } //显示时循环list就可以了
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
<view class="list" wx:for="{{list}}" wx:for-index="key" wx:for-item="val">
<view class="label">标题内容</view>
<picker mode="selector" value="{{val.express.key}}" data-key="{{key}}" range="{{express}}" range-key="name" bindchange="express_change">
{{val.express.name ||'点击选择快递'}}
</picker>
</view>
<button bind:tap="item_add">添加项目</button>
Page({
data: {
list :[
{express : {key:0,name:''},address: ''},
],
express : [
{name:'中通1'},
{name:'中通2'},
{name:'中通3'},
{name:'中通4'}
]
},
onLoad() {
item_add : function(){
let items = this.data.list;
let item = {express:{key:-1,name:''},address:'' };
items.push(item);
this.setData({
list : items
})
express_change:function(e){
console.log(e);
let express = this.data.express[e.detail.value];
let key = e.target.dataset.key;
let list = this.data.list;
list[key].express = {key : key, name:express.name};
list :list
}
快递公司和收件地址这块用for循环渲染,增加取件点击后给循环渲染的数组push一条数据就好
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
按你的要求,我可能会这样子处理
let list = []; //点击添加 add:(){ let item = {express :'',address:''}; list.push(item); } //显示时循环list就可以了
<view class="list" wx:for="{{list}}" wx:for-index="key" wx:for-item="val">
<view class="label">标题内容</view>
<picker mode="selector" value="{{val.express.key}}" data-key="{{key}}" range="{{express}}" range-key="name" bindchange="express_change">
{{val.express.name ||'点击选择快递'}}
</picker>
</view>
<button bind:tap="item_add">添加项目</button>
Page({
data: {
list :[
{express : {key:0,name:''},address: ''},
],
express : [
{name:'中通1'},
{name:'中通2'},
{name:'中通3'},
{name:'中通4'}
]
},
onLoad() {
},
item_add : function(){
let items = this.data.list;
let item = {express:{key:-1,name:''},address:'' };
items.push(item);
this.setData({
list : items
})
},
express_change:function(e){
console.log(e);
let express = this.data.express[e.detail.value];
let key = e.target.dataset.key;
let list = this.data.list;
list[key].express = {key : key, name:express.name};
this.setData({
list :list
})
}
})
快递公司和收件地址这块用for循环渲染,增加取件点击后给循环渲染的数组push一条数据就好