国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 課堂 > 小程序 > 正文

微信小程序?qū)崿F(xiàn)用table顯示數(shù)據(jù)庫反饋的多條數(shù)據(jù)功能示例

2020-03-21 15:57:30
字體:
供稿:網(wǎng)友

本文實(shí)例講述了微信小程序實(shí)現(xiàn)用table顯示數(shù)據(jù)庫反饋的多條數(shù)據(jù)功能。分享給大家供大家參考,具體如下:

解決了微信小程序自定義表格,并顯示的多條數(shù)據(jù)的問題。

index.wxml

<view> <text>我的調(diào)查問卷</text> <scroll-view scroll-x="true" style=" white-space: nowrap; display: flex"> <view class="table">  <view class="tr bg-header">   <view class="th">姓名</view>    <view class="th">性別</view>   <view class="th">年齡</view>  </view>  <view class="tr bg-items" wx:for = "{{items}}" wx:key="">    <text class="td">{{item.name}}</text>   <text class="td">{{item.gender}}</text>   <text class="td">{{item.age}}</text>  </view> </view> </scroll-view> <button bindtap="change">查看我的數(shù)據(jù)</button></view>

index.js

Page({ /**  * 頁面的初始數(shù)據(jù)  */ data: {  items:[]//定義變長數(shù)組 }, /**  * 生命周期函數(shù)--監(jiān)聽頁面加載  */ onLoad: function () { }, /**  * 生命周期函數(shù)--監(jiān)聽頁面顯示  */ onShow: function () { }, /**  * 生命周期函數(shù)--監(jiān)聽頁面隱藏  */ onHide: function () { }, change:function(e){  var that=this;  wx.request({   url: 'https://../data.php',//自己的服務(wù)器地址   header: {    "Content-Type": "application/json"   },   method: "POST",   success: function (res) {    for (var i = 0, len = res.data.length; i < len; i++){     that.data.items[i] = res.data[i];    }    that.setData({     items: that.data.items    })   },   fail: function (res) {    wx.showToast({     'title': 'request fail'    })   }  }) }})

data.php

<?php$servername = "localhost";$username = "root";$password = "***";//數(shù)據(jù)庫連接密碼$dbname = "mydb";// 創(chuàng)建連接$conn = new mysqli($servername, $username, $password, $dbname);// 檢測連接if ($conn->connect_error) { die("connect server fail: " . $conn->connect_error);}$query = "select * from table";$result = mysqli_query($conn,$query);$data = array();while ($rows = mysqli_fetch_assoc($result)){$data[] = $rows;}echo json_encode($data);$conn->close();?>

文章有借鑒,并非全部自創(chuàng)

希望本文所述對大家微信小程序開發(fā)有所幫助。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 贵溪市| 辽阳县| 崇文区| 扎赉特旗| 昌吉市| 德江县| 全椒县| 葵青区| 遂川县| 海南省| 巴彦县| 即墨市| 皋兰县| 抚宁县| 改则县| 榆中县| 普宁市| 惠州市| 竹山县| 赤峰市| 英超| 黄平县| 舞阳县| 宁夏| 明溪县| 西丰县| 安陆市| 杂多县| 修武县| 桑植县| 贵定县| 越西县| 满城县| 巴林左旗| 尚义县| 海晏县| 象山县| 南岸区| 毕节市| 南充市| 紫阳县|