1、列表index下标取值
实现方式:data-index="{{index}}"挖坑及e.currentTarget.dataset.index来填坑即可
wxml:
<
view
wx:for=
"{{adress}}"
bindtap=
'delete'
wx:key=
"{{adress}}"
data-index=
"{{index}}">
<
text
>{{item.name}}
</
text
>
<
text
class=
'red'>删除
</
text
>
</
view
>
JS:
adress:[
{
id:
100,
name:
"我是内容1"
}, {
id:
101,
name:
"我是内容2"
}, {
id:
102,
name:
"我是内容3"
}
]
delete:function(e){
var index = parseInt(e.currentTarget.dataset.index);
console.log(
"index:" + index);
//取出值
var that =
this;
var address = that.data.adress[index];
// 给出确认提示框
wx.showModal({
title:
'确认',
content:
'要删除这个地址吗?',
success:
function(res) {
console.log(
"删除成功");
}
})
}
2.1、通过wx.navigateTo()拼接url传递参数
2.1.1、 基本类型:url:'url?key='+value
2.1.2、 传递对象
2.1.3、 传递数组集合
2.2、App.js设置全局变量
2.3、数据缓存再获取
主要说下第一种拼接url:
adress:[
{
id:
100,
name:
"我是内容1"
}, {
id:
101,
name:
"我是内容2"
}, {
id:
102,
name:
"我是内容3"
}
],
testData: { name:
'username', password:
'password' },
list: [
'item-A',
'item-B']
}
navTo:
function(e){
var that =
this;
var index = parseInt(e.currentTarget.dataset.index);
var id = that.data.adress[index].id;
wx.navigateTo({
url:
'valueGet?id='+id,
})
},
navToObject:
function(e){
wx.navigateTo({
url:
'valueGet?testData=' + JSON.stringify(
this.data.testData)
})
},
navToObject1:
function (e) {
wx.navigateTo({
url:
'valueGet?list=' + JSON.stringify(
this.data.list)
})
}
3、form表单取值
通过form bindsubmit="formSubmit"与button formType="submit"标签配合使用
<
form
bindsubmit=
"formSubmit">
<
input
name=
"detail"
placeholder=
"详情地址"
/
>
<
input
name=
"realname"
placeholder=
"收件人姓名"
/
>
<
input
name=
"mobile"
placeholder=
"手机号码"
type=
"number"
/
>
<
button
formType=
"submit"
type=
"primary">Submit
</
button
>
</
form
>
formSubmit:
function(e){
// detail
var detail = e.detail.value.detail;
console.log(
"detail:"+detail);
// realname
var realname = e.detail.value.realname;
console.log(
"realname:" + realname);
// mobile
var mobile = e.detail.value.mobile;
console.log(
"mobile:" + mobile);
}