weixin_45835034 2020-11-04 15:51
浏览 231

如何将picker的值同input的值一同上传到云数据库?

wxml:

<form bindsubmit="sp_fabu">
<view class="leixing">
  <picker bindchange="bindPickerChange" value="{{lx_index}}" range="{{lx_array}}">
    <view class="leixing_1" name = "lx_index">
      商品类型:{{lx_array[lx_index]}}
    </view>
  </picker>
</view>

<view class="biaoti">
   <input name="sp_biaoti" class="biaoti_1" maxlength="15" placeholder="商品标题(限定字数15以内~)" />
</view> 

<view class="jieshao">
   <textarea name="sp_jieshao" class="jieshao_1" maxlength="100" placeholder="商品介绍(限定字数100以内~)" />
</view>



<view class="jiage">
   价格:<input name="sp_jiage" type="number" class="jiage_1" maxlength="15" placeholder="商品价格" />
</view> 

<view class="lianxi">
  联系方式: <input name="sp_phone" type="number" class="lianxi_1" maxlength="11" placeholder="手机号码" />
</view> 

<button bindtap="tofabu" class="btn" size="large" form-type="submit">确认发布</button>

</form>

js:

const db = wx.cloud.database()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lx_array: ['数码', '日化', '虚拟', '资料','服装'],
    objectArray: [
      {
        id: 0,
        name: '数码'
      },
      {
        id: 1,
        name: '日化'
      },
      {
        id: 2,
        name: '虚拟'
      },
      {
        id: 3,
        name: '资料'},
        {
          id: 4,
          name: '服装'},

      ],
        lx_index: 0,
    "lx_index":"",
    "sp_biaoti":"",
    "sp_jieshao":"",
    "sp_jiage":"",
    "sp_phone":"",
    "sp_time":"",

  },
  //改变商品类型
  bindPickerChange: function(res) {
    console.log('picker发送选择改变,携带值为', res.detail.value)
    this.setData({
      lx_index: res.detail.value
    })
  },
  //向sp_fabu发送数据
  sp_fabu:function(res){
    console.log(res)
    var lx_index = res.detail.value.lx_index
    var sp_biaoti = res.detail.value.sp_biaoti
    var sp_jieshao = res.detail.value.sp_jieshao
    var sp_jiage = res.detail.value.sp_jiage
    var sp_phone = res.detail.value.sp_phone
    var sp_time = Date()

    wx.showLoading({
      title: '数据正在提交中......',
      mask:"true"
    })
    db.collection("cs").add({
      data:{
        "lx_index": lx_index,
       "sp_biaoti": sp_biaoti,
       "sp_jieshao": sp_jieshao,
       "sp_jiage": sp_jiage,
       "sp_phone": sp_phone,
       "sp_time": Date()

      }
    }).then(res=>{
      console.log(res)
      wx.hideLoading()
    })
  },

})
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求解 yolo算法问题
    • ¥15 虚拟机打包apk出现错误
    • ¥30 最小化遗憾贪心算法上界
    • ¥15 用visual studi code完成html页面
    • ¥15 聚类分析或者python进行数据分析
    • ¥15 逻辑谓词和消解原理的运用
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。