微信小程序:表格中更改输入框的值,实时获取表格全部数据,点击按钮更改数据库指定项数据

这篇具有很好参考价值的文章主要介绍了微信小程序:表格中更改输入框的值,实时获取表格全部数据,点击按钮更改数据库指定项数据。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

样例:

样式展示

点击按钮更改数据库,微信小程序,数据库,小程序

数据库中原始第一条数据

点击按钮更改数据库,微信小程序,数据库,小程序

 修改表格第一行的数量:

点击按钮更改数据库,微信小程序,数据库,小程序

数据库结果 

 点击按钮更改数据库,微信小程序,数据库,小程序

 核心代码

wxml

①wx:for:执行循环将数组数据展示出来

②在某一单元格加上input样式

③在input中绑定:文本框改变事件,并且绑定data-index便于知道改变的具体是哪一行的数据

<!-- 表格 -->
<view class="table_position">
    <view class="table">
        <view class="table-tr">
            <view class="table-th1">顺序</view>
            <view class="table-th2">制程</view>
            <view class="table-th3">数量</view>
          </view>
        <view class="table-tr" wx:for="{{allinfo}}" wx:key="unique">
           <view class="table-td1">{{item.operation_seq_num}}</view>
           <view class="table-td2">{{item.operation_code}}</view>
           <view class="table-td3">
             <view class="input_position">
               <input type="text" value="{{item.begin_quantity}}" class="input" bindinput="inputChange" data-index="{{index}}"/>
             </view>
           </view>
        </view>
    </view>
</view>
<!--开始生产的按钮-->
<view class="start">
    <view class="button_text" bindtap="start_produce">开始生产</view>
</view>

wxss

/* 表格样式 */
.table_position{
  padding:15px;
}
.table {
  display: table;
  width: 100%;
  border-collapse: collapse;
  box-sizing: border-box;
}
.table-tr {
  display: table-row;
}
.table-th1 {
  width:10%;
  display: table-cell;
  font-weight: bold;
  border: 1rpx solid white;
  background-color:#51aad6;
  text-align: center;
  vertical-align: middle;
  padding: 5px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}
.table-th2 {
  width:20%;
  display: table-cell;
  font-weight: bold;
  border: 1rpx solid white;
  background-color:#51aad6;
  text-align: center;
  vertical-align: middle;
  padding: 5px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}
.table-th3 {
  width:15%;
  display: table-cell;
  font-weight: bold;
  border: 1rpx solid white;
  background-color:#51aad6;
  text-align: center;
  vertical-align: middle;
  padding: 5px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}
.table-td1{
  width:10%;
  display: table-cell;
  text-align: center;
  vertical-align: middle;
  padding: 5px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
  border: 1rpx solid white;
  background-color:#aacee0;
}
.table-td2 {
  width:20%;
  display: table-cell;
  text-align: center;
  vertical-align: middle;
  padding: 5px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
  border: 1rpx solid white;
  background-color:#aacee0;
}
.table-td3 {
  width:15%;
  display: table-cell;
  text-align: center;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
  border: 1rpx solid white;
  background-color:#aacee0;
  /* padding: 5px 0; */
}
/* 输入框的样式 */
.input_position{
  display: flex;
  justify-content: center;
  align-items: center;
}
.input{
  background-color:rgb(255, 255, 255);
  width:70%;
  text-align:left;
}
/* 开始训练的按钮 */
.start{
  margin-top:10%;
  width:100%;
  display: flex;
  justify-content:center;
  align-items: center;
}
.button_text{
  background-color:rgb(245, 196, 196);
  width:90%;
  text-align:center;
  padding:2%;
}

js

①变更input,获取表格的全部数据

event.currentTarget.dataset.index:获取行信息

2° event.detail.value:获取输入的数据值

3° this.data.allinfo:获取原数组的信息

4° allinfo[index].begin_quantity = newValue;:找到修改的行的信息,将这一行对应的文本框的值修改为用户输入的值

// 输入框内容改变时,更新对应数据
  inputChange: function (event) {
    var index = event.currentTarget.dataset.index;
    var newValue = event.detail.value;
    var allinfo = this.data.allinfo;
    allinfo[index].begin_quantity = newValue;
    this.setData({
      allinfo: allinfo
    });
    console.log(this.data.allinfo)
  },

②点击开始按钮执行事件

1°提示确认图片展示

点击按钮更改数据库,微信小程序,数据库,小程序

JSON.stringify(this.data.allinfo):将数组转换为json格式便于后端处理

  //开始生产
  start_produce(){
    wx.showModal({
      title:'生产确认',
      content: '确认生产'+this.data.order_number+'?',
      success:res=>{
        //点击确认
        if(res.confirm){
          wx.request({
            url: app.globalData.position + 'Produce/start_produce',
            data: {
              order_number: this.data.order_number,
              username: app.globalData.username,
              allinfo:JSON.stringify(this.data.allinfo)
            },
            header: {
              "Content-Type": "application/x-www-form-urlencoded"
            },
            method: 'POST',
            dataType: 'json',
            success: res => {
              console.log(res.data)
              this.onLoad()
            },
            fail(res) {
              console.log("查询失败")
            }
          })
        }
        //点击取消
        else{
          console.log('用户点击了取消')
        }
      }
    })
  }

js完整代码

const app = getApp()
Page({
  //数据信息
  data: {},
  //刚进入页面执行的操作
  onLoad(options) {
    var pages = getCurrentPages()
    var currentPage = pages[pages.length - 1] //获取当前页面的对象
    var options = currentPage.options //如果要获取url中所带的参数可以查看options
    this.setData({
      order_number: options.order_number
    })
    //查询单号对应的信息
    wx.request({
      url: app.globalData.position + 'Produce/select_operation',
      data: {
        order_number: this.data.order_number,
        username: app.globalData.username
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      method: 'POST',
      dataType: 'json',
      success: res => {
        console.log(res.data)
        this.setData({
          allinfo: res.data.info,
          employee_name: res.data.employee_name
        })
      },
      fail(res) {
        console.log("查询失败")
      }
    })
    // console.log(options.order_number) 
  },
  // 输入框内容改变时,更新对应数据
  inputChange: function (event) {
    var index = event.currentTarget.dataset.index;
    var newValue = event.detail.value;
    var allinfo = this.data.allinfo;
    allinfo[index].begin_quantity = newValue;
    this.setData({
      allinfo: allinfo
    });
    console.log(this.data.allinfo)
  },
  //开始生产
  start_produce(){
    wx.showModal({
      title:'生产确认',
      content: '确认生产'+this.data.order_number+'?',
      success:res=>{
        //点击确认
        if(res.confirm){
          wx.request({
            url: app.globalData.position + 'Produce/start_produce',
            data: {
              order_number: this.data.order_number,
              username: app.globalData.username,
              allinfo:JSON.stringify(this.data.allinfo)
            },
            header: {
              "Content-Type": "application/x-www-form-urlencoded"
            },
            method: 'POST',
            dataType: 'json',
            success: res => {
              console.log(res.data)
              this.onLoad()
            },
            fail(res) {
              console.log("查询失败")
            }
          })
        }
        //点击取消
        else{
          console.log('用户点击了取消')
        }
      }
    })
  }
})

PHP

json_decode($_POST['allinfo'], true);将前端传来的json格式的数组解析为普通数组

②对数组进行循环

③获取数组中每项对应的id

④根据id,去修改数据库中的单项值文章来源地址https://www.toymoban.com/news/detail-601599.html

 public function start_produce(){
      $wip_entity_name = input('post.order_number');
      $username = input('post.username');
      $allinfo = json_decode($_POST['allinfo'], true);
      for($i = 0 ; $i<count($allinfo); $i++){
        //获取数组中的每行的id
        $id = $allinfo[$i]['wip_operation_id'];
        // 更改数据库中每站开始数量的值
        db::table('wip_operation_plan')
        ->where(
          [
            'wip_operation_id'=>$id
          ]
        )
        ->update(
          [
            'begin_quantity'=>$allinfo[$i]['begin_quantity']
          ]
        );
       
      }
      $data['info'] = db::table('wip_operation_plan')->where(['wip_entity_name'=>$wip_entity_name])->select();
      echo json_encode($data);
    }

到了这里,关于微信小程序:表格中更改输入框的值,实时获取表格全部数据,点击按钮更改数据库指定项数据的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • element-ui 表单中,下拉框选中某个值后,同步更新其他输入框的值

    element-ui 表单中,下拉框选中某个值后,同步更新其他输入框的值

    设置选择后的@change事件 参考链接: https://www.cnblogs.com/zhangxue521/p/14518175.html

    2024年02月16日
    浏览(10)
  • 微信小程序(第七章)- 搜索框的实现

    外部容器i 内部容器 两者关系:外部容器包裹内部容器,而且内部容器正好在we外部容器的居中(水平垂直居中)位置。 可在微信小程序中使用view,可以在view里面定义内容。 wxml文件 - html文件 wxss文件 - css文件 js文件 -js文件 json文件 - 配置文件 删除index.wxml里面的demo(模板)代

    2024年02月09日
    浏览(11)
  • vue+Element UI 实现动态表单(点击按钮增删表格及嵌套输入框的增删)(1)

    vue+Element UI 实现动态表单(点击按钮增删表格及嵌套输入框的增删)(1)

    el-button size=“small” @click=“addTable”新增 el-button size=“small” @click=“delTable”删除 el-table ref=“table” :data=“tableDataBind.taAssessltems” tooltip-effect=“dark” border @selection-change=“selectRow” 规格: 重量: 数量: 加工费: el-button size=“mini” type=“primary” icon=“el-icon-circle-plus-ou

    2024年04月13日
    浏览(17)
  • 关于微信小程序,如何更改微信小程序的名字

    关于微信小程序,如何更改微信小程序的名字

    当我们前期开始创作小程序的时候,因为业务范围不确定也好,或者是随便起了名字 在发布前或者发布后觉得不恰当想要更改小程序的名字   方法: 1.百度搜索\\\"微信公众平台\\\",或者直接进入网址:   微信公众平台 微信公众平台,给个人、企业和组织提供业务服务与用户管理能力

    2024年02月09日
    浏览(13)
  • 微信小程序多列下拉框的实现(树形数据结构和单数组数据结构形式)

    微信小程序多列下拉框的实现(树形数据结构和单数组数据结构形式)

    利用微信小程序api,实现不同传输数据格式下的多列下拉框实现 首先了解一下picker中的事件 这里是官方文档,具体意思就是 当你滑动多列中的某一列的时候, bindcolumnchange 事件就会触发。当选择完毕点击确定的时候 bindchange 事件就会触发 微信小程序的多列下拉框是真的反人

    2024年02月07日
    浏览(13)
  • 微信小程序更改头像昵称

    目录 背景 解决思路 前面写了一篇关于小程序头像昵称获取更改的方案,有很多小伙伴私信我发一个整体的逻辑思路! 前面的这篇文章中我们给出了页面中获取头像昵称的代码: 上方代码中我们可以很清晰的看到用户的头像和昵称,使用button和input输入框来填充或者更改的。

    2024年02月09日
    浏览(9)
  • 微信小程序this.setData修改对象、数组中的值

    在微信小程序的[前端开发]中,使用this.setData方法修改data中的值,其格式为: 需要注意的是,如果是简单变量,这里的参数名可以不加引号。 经过测试,可以使用3种方式对data中的对象、数组中的数据进行修改。 假设原数据为: 方式一: 使用字符串,例如: 方式二: 构造

    2024年02月10日
    浏览(10)
  • 微信小程序checkbox,checkbox-group多选框的简易用法,代码简洁,可复用性高

    首先这是官网的用法: 代码非常的长,而且很难复用 (不能多个复选框共用这个checkboxChange方法) 划分线,下面是更好的写法 触发checkboxChange的时候传一个key值过去,之后值对应的是一个新数组(与下面wx:for的数组不同),用来存放已选择的项 因为 微信小程序中我们不能直

    2024年02月11日
    浏览(13)
  • 微信小程序button按钮无法更改尺寸解决

    微信小程序button按钮无法更改尺寸解决

    在微信小程序新版本中, button按钮 无法支持在wxss文件中 直接自定义width 和 height   解决方法有两种:         1. 推荐使用: 在根目录中的app.json文件中, 删除其中的 即可, 但影响性较大, 如果项目中的其他样式 使用了新版本的特性, 则 删除该行代码后 项目中的其他样式 可能会

    2024年02月15日
    浏览(45)
  • 微信小程序基础库的介绍与更改

    微信小程序基础库的介绍与更改

    一、什么是基础库? 1、基础库是小程序运行的必要环境, 我们的开发主要就是面向基础库开发的 。基础库封装了微信和手机的能力并提供给小程序使用,我们使用基础库提供的组件和API开发起来非常的方便。 2、基础库存在于我们的微信客户端中,它和微信一样,也有其自

    2024年02月13日
    浏览(11)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包