小程序模板網(wǎng)

最新攜程小程序初體驗

發(fā)布時間:2018-06-21 10:13 所屬欄目:小程序開發(fā)教程

功能效果如下

 

 

查詢功能的實(shí)現(xiàn)

1.首先需要在查詢之前獲取輸入的所在城市以及到的城市,以及時間的選擇,通過這些條件去篩選,所以需要在點(diǎn)擊查詢按鈕的時候綁定一個時間,需要攜帶參數(shù)去進(jìn)行查詢


<navigator class="search"  url="/pages/trainBuyContent/trainBuyContent?from={{from}}&to={{to}}&trainTime={{startDate}}">查詢</navigator>

2.需要到跳轉(zhuǎn)的頁面接收參數(shù)通過onload事件的options獲取


    var from = options.from;
    var to = options.to;
    var trainTime = options.trainTime;

3.最重要的是篩選出相關(guān)數(shù)據(jù),這里需要一個for循環(huán)的判斷語句,在請求數(shù)據(jù)地址URL的時候,通過for循環(huán)和if語句找出相對應(yīng)的數(shù)據(jù)文件里面所對應(yīng)的json數(shù)據(jù)。


wx.request({
      url: API_BASE,
      success: (res) => {
        for(var i=0;i<res.data.data.trainList.length;i++){
          if (from == res.data.data.trainList[i].from && to == res.data.data.trainList[i].to && trainTime == res.data.data.trainList[i].trainTime){
            temp.push(res.data.data.trainList[i]);
          }
        }
        this.setData({
          searchedList:temp
        })
      }
    })

4.這時候再在頁面通過for循環(huán)輸出就可以了


wx:for="{{searchedList}}"
wx:key="{{item.id}}"
temp.push(res.data.data.trainList[i]);
this.setData({
          searchedList:temp
        })

*小程序頁面?zhèn)髦档姆绞剑?.url傳值2.本地儲存3.全局的app對象

訂單查詢的實(shí)現(xiàn)

這里我采用了全局的app對象保存

1.先獲取全局對象,然后在點(diǎn)擊確定購買的success回調(diào)函數(shù)的時,去獲取所有的信息,以一個json格式去獲取


const app = getApp();
var trainedList = app.globalData.trainedList;
var trainItem = {
          from: this.data.from, 
          to: this.data.to,  
          trainNum: this.data.trainNum,
          trainTime: this.data.trainTime,
          totalPrice: this.data.totalPrice
        };
trainedList.push(trainItem);

2.然后在相應(yīng)的頁面去獲取這個全局的數(shù)組


onLoad: function (options) {
    this.setData({
      trainedList: app.globalData.trainedList
    })
    
  },

3.通過一個for循環(huán)讓其輸出在頁面

 

 

其他功能

還有一部分功能未能展示或者未完善,請大家見諒。

 

小總結(jié)

第一次發(fā)表文章有點(diǎn)小慌張,寫的不好希望大家諒解,說實(shí)話,在我看來,這次所寫的東西確實(shí)有點(diǎn)'糙',但還是很開心自己能堅持寫下來,功能方面以后會繼續(xù)完善,希望能得到各位大佬們的意見和建議,沒啥說的,繼續(xù)努力吧,路漫漫其修遠(yuǎn)兮,Just do it!

 



易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.u-renovate.com/wxmini/doc/course/24572.html 復(fù)制鏈接 如需定制請聯(lián)系易優(yōu)客服咨詢:800182392 點(diǎn)擊咨詢
QQ在線咨詢
AI智能客服 ×