假设我input 身高100 体重100 picker “男”, 点击 calculate后就运行公式:身高+体重+10= 210
如果我的picker 是女,点击calculate则运行 公式: 身高+体重+100=300
我目前遇到的问题是 picker 无法切换 且 calculate 按钮 没反应
WXML:
<view class="btnGroup">
<input class="input" bindinput="heightinput" name="height" type="digit" placeholder="height in cm"/>
<input class="input" bindinput="weightinput" name= "weight" type="digit" placeholder="current weight in kg"/>
</view>
<view class="section__title">普通选择器</view>
<picker bindchange="bindPickerChange" value="{{index}}" range="{{array}}">
<view class="picker">
当前选择:{{array[index]}}
</view>
</picker>
身高:{{height}}
体重:{{weight}}
计算结果:{{result}}
<view style="display:flex;margin-top:40rpx;">
<button type="warn"
bindtap="FINAL"
style="width:100%;" formType="submit" >CALCULATE</button>
</view>
WXJS:
const app = getApp()
const compute = function (height, weight, gender) {
if (gender === 'Male') {
return height + weight;
} else {
return height + weight + 10;
}
}
Page({
data: {
array: ['Male', 'Female'],
index: 0,
result: 0,
height: "",
weight: "",
},
//获取用户输入的height值
heightinput: function (e) {
this.setData({
height: e.detail.value })},
//获取用户输入的weight值
weightinput: function (e) {
this.setData({
weight: e.detail.value })},
bindPickerChange: function (e) {
console.log('picker发送选择改变,携带值为', e.detail.value)
const index = e.detail.value;
const gender = this.data.array[index];
const result = compute(heightinput, weightinput, gender)
this.setData({
index,
result
})
},
})
https://developers.weixin.qq.com/s/NcY4r6mS7khx
开发不看控制台信息吗,肯定有报错啊。
这个函数里heightinput和weightinput在哪定义的?????
我是用了一个function:
heightinput: function (e) {
this.setData({
height: e.detail.value })},
请问怎么把 用户输入的height值放到另一个函数里面?