欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2019年05月07日 11:54:05   作者:清風(fēng)思月  
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)用table顯示數(shù)據(jù)庫(kù)反饋的多條數(shù)據(jù)功能,涉及微信小程序wx.request訪問(wèn)php后臺(tái)及返回結(jié)果的顯示布局相關(guān)操作技巧,需要的朋友可以參考下

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

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

index.wxml

<view>
 <text>我的調(diào)查問(wèn)卷</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({
 /**
  * 頁(yè)面的初始數(shù)據(jù)
  */
 data: {
  items:[]//定義變長(zhǎng)數(shù)組
 },
 /**
  * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載
  */
 onLoad: function () {
 },
 /**
  * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示
  */
 onShow: function () {
 },
 /**
  * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面隱藏
  */
 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ù)庫(kù)連接密碼
$dbname = "mydb";
// 創(chuàng)建連接
$conn = new mysqli($servername, $username, $password, $dbname);
// 檢測(cè)連接
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)

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

相關(guān)文章

最新評(píng)論