Page({
/**
* 頁面的初始數據
*/
data: {
array: []
},
/**
* 生命周期函數--監聽頁面加載
*/
onLoad: function (options) {
var that = this;
console.log("start");
//ajax請求開始
wx.request({
url: '', //ajax的請求路徑
method: "get", //ajax的請求方法
//header是配置,根據后台配的來的 header: { 'app-id': app.globalData.app_id, 'AUTHORIZATION': token }, success: (res) => { let dataList = res.data.results; //獲取到的數據 dataList.forEach((item) => { item.submit_time = item.submit_time.substring(0, 10); //要截取字段的字符串 }) that.setData({ array: dataList //數據源 }) } }) } })
以上wx.request方法來獲取數據,其中forEach循環dataList,使用substring方法來截取想要的字符串。
