网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

微信小程序開發--條件渲染詳解

發布時間:2017-12-29 18:05 所屬欄目:小程序開發教程

這里先寫一下布局的代碼和js效果代碼,細節有空再補充

<!--index.wxml-->
<!--主頁模塊-->
<block wx:if="{{condition}}">
  <view class="content">
    <view class="current_box center">
      <view class="current_city center">
        <text>當前城市:</text>
        <text>{{city}}</text>
      </view>
    </view>
    <view class="start_box text_center" bindtap="startEvent">
      <text class="start">起點</text>
      <text class="set_out">{{startData}}</text>
    </view>
    <view class="end_box text_center" bindtap="endEvent">
      <text>終點</text>
      <text>{{endData}}</text>
    </view>
    <view class="find_box center">
      <view class="find center" bindtap="findEvent">
        <text class="find_text">查詢</text>
      </view>
    </view>
  </view>
</block>
<!--請輸入起點模塊-->
<block wx:if="{{start}}">
  <view class="start_search_box">
    <view class="searches center">
      <view class="search text_center">
        <text class="search_text center">search</text>
        <input class="search_input center"  type="text" placeholder="請輸入起點" bindinput="startInputEvent"/>
        <text class="search_back center" bindtap="startBackEvent">back</text>
      </view>
    </view>
    <view class="location_box center">
      <view class="location">
        <text class="location_text align_center">我的位置:</text>
        <text class="location_city align_center">{{address}}</text>
      </view>
    </view>
  </view>
</block>

<!--請輸入起點-展示模塊-->
<block wx:if="{{isShow}}">
  <view class="start_show_box center">
    <view class="start_show_content">
      <view class="start_content align_center" wx:key="unique" bindtap="startItemEvent" wx:for="{{array}}" data-index="{{index}}">
        {{index}}:{{item.name}}
      </view>
    </view>
  </view>
</block>
<!--請輸入終點模塊-->
<block wx:if="{{end}}">
  <view class="end_search_box center">
    <view class="end_search text_center">
      <text class="search_text">search</text>
      <input type="text" placeholder="請輸入終點" bindinput="endInputEvent" />
      <text class="search_back" bindtap="endBackEvent">back</text>
    </view>
  </view>
</block>
<!--請輸入終點-展示模塊-->
<block wx:if="{{isTrue}}">
  <view class="end_show_box center">
   <view class="end_show_content">
    <view class="end_content align_center" bindtap="endItemEvent" wx:for="{{arrays}}" wx:key="unique" data-index="{{index}}">
     {{index}}:{{item.name}}
    </view>
   </view>
  </view>
</block>
<!--查詢路線模塊-->
<block wx:if="{{isInquiry}}">
  <view class="inquiry_box center">
  <view class="inquiry_content">
    <view class="inquiry_content_list center">
    {{startData}} -> {{endData}}
    </view>
  </view>
</view>
</block>
<!--測試模塊-->
<!--<view class="test">
  <text bindtap="testEvent">test</text>
</view>-->



js代碼:

//index.js
//獲取應用實例
var app = getApp()
Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    city: '北京',
    startData: '從哪兒出發',
    endData: '要去哪兒',
    address: '同城街',
    condition: true,
    start: false,
    end: false,
    isShow: false,
    isTrue: false,
    isInquiry: false,
    city: "深圳市",
    inputData: "", //search頁面輸入框的數據
    array: [],
    arrays: []
  },
  /**
   *  函數名:findEvent
   *  功能:當點擊主頁查詢按鈕時,
   *  如果起點和終點沒有數據的話,需要提示請輸入地點
   *  如果有起點和終點的話,需要隱藏主頁,顯示新的頁面(提供路線的頁面)
   */
  findEvent: function(){
    let _this = this;
    console.log(this.data.array.length);
    if( this.data.array.length > 0 && this.data.arrays.length > 0){
      _this.setData({
        condition: false,
        isInquiry: true,
      })
    }else{
      wx.showLoading({
        title: '請選擇地點',
      })
      setTimeout(function () {
        wx.hideLoading()
      }, 2000)
    }
  },
  /**
   *  函數名:startEvent
   *  功能:主頁面模塊隱藏
   *       起點頁面顯示
   */
  startEvent: function(){
    //console.log("aa");
    //console.log(this);
    this.setData({
      condition: false,
      start: true,

    })
  },
  /**
   *  函數名:endEvent
   *  功能: 主頁面模塊隱藏
   *        終點頁面顯示
   */
  endEvent: function(){
    //console.log("bb");
    this.setData({
      condition: !this.data.condition,
      end: !this.data.end
    })
  },
  /**
   *  函數名:startDeleteEvent
   *  功能:點擊起點輸入框中的back按鈕返回到主頁面
   *       
   */
  startBackEvent: function(){
    this.setData({
      condition: true,
      start: false,
      isShow: false
    })
  },
  /**
   *  函數名:endBackEvent
   *  功能:點擊終點輸入框中的back按鈕終返回主頁面
   * 
   */
  endBackEvent: function(){
    //console.log("endDeleteEvent");
    this.setData({
      condition: true,
      end: false
    })
  },
  /**
   *  函數名:startInputEvent
   *  功能: 在請輸入起點框中輸入內容時,觸發此函數
   */
  startInputEvent: function(e){
    console.log("startInputEvent");
    var _this = this;
    let data = e.detail.value;
    //console.log("data",data);
    this.setData({
      isShow: true,
    })
    wx.request({
      //非真實接口,僅為示例
      url: "https://w.mmm.com/search2016/search/keywords",
      data: {
        keywords: data,
        city: 110000
      },
      method: 'GET',
      success: function(res){
        console.log(res.data.pois);
        //console.log(res.data.pois[0].city);
        _this.setData({
          array: res.data.pois
        })
      },
      fail: function(){
        console.log("請求失敗");
      }
    })
  },
  /**
   *  函數名:endInputEvent
   *  功能:在請輸入終點框中輸入內容時觸發此函數
   */
  endInputEvent: function(e){
    console.log("endInputEvent");
    var _this = this;
    let data = e.detail.value;
    console.log(data);
    this.setData({
      isTrue: true,
    })
    wx.request({
      url: 'https://w.mmm.com/search2016/search/keywords',
      data: {
        keywords: data,
        city: 110000
      },
      method: 'GET',
      success: function(res){
        //console.log(res);
        _this.setData({
          arrays: res.data.pois
        })
      },
      fail: function(){
        console.log("請求失敗!");
      }
    })
  },
  /*
   *  函數名:startItemEvent
   *  功能: 點擊渲染到的每一項,然后替換起點里面的值
   *  遇到的問題:
   *  1.怎么樣獲取每一項的值,然后改變起點的位置
   *  用 data-index = {{index}}
   *  2.如何才能獲取我點擊那一項對應的值
   *  獲取i
   *  var i = e.target.dataset.index;
   *  不懂的話可以打出e看是什么東西
   *  
  */
  startItemEvent: function(e){
    console.log(e);
    var i = e.target.dataset.index;
    var itemList = this.data.array;
    console.log("itemList",itemList[i].name);
    var startItemData = itemList[i].name;
    this.setData({
      isShow: false,
      start: false,
      condition: true,
      startData: startItemData
    })
  },
  /**
   *  函數:endItemEvent
   *  功能:當點擊渲染出來的每一項時,讓去哪兒改變數據
   */
  endItemEvent: function(e){
    console.log(e);
    var i = e.target.dataset.index;
    var itemList = this.data.arrays;
    console.log("itemList", itemList[i].name);
    var endItemData = itemList[i].name;
    this.setData({
      condition: true,
      end: false,
      isTrue: false,
      endData: endItemData
    })
  },
  //事件處理函數
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  testEvent: function(){
    wx.navigateTo({
      url: "/pages/test/test"
    })
  },
  onLoad: function () {
    console.log('onLoad')
    //console.log(this);
    var that = this;
    //調用應用實例的方法獲取全局數據
    app.getUserInfo(function(userInfo){
      //更新數據
      that.setData({
        userInfo:userInfo
      })
    })
  }
})

樣式代碼:

/**index.wxss**/
.content{
    width: 100%;
    height: 100%;
}
.current_box{
    width: 100%;
    height: 60rpx;
    border-bottom: 2rpx solid #ccc;
}
.start_box{
    width: 100%;
    height: 80rpx;
    border-bottom: 2rpx solid #ccc;
}
.start_show_box{
    width: 100%;
    height: auto;
    background: #f99;
}
.start_show_content{
    width: 90%;
    height: auto;
}
.start_content{
    width: 100%;
    height: 60rpx;
    background: yellow;
    margin: 10rpx 0;
}
.end_box{
    width: 100%;
    height: 80rpx;
    border-bottom: 2rpx solid #ccc;
}
.end_show_box{
    width: 100%;
    height: auto;
    background: #f99;
}
.end_show_content{
    width: 90%;
    height: auto;
}
.end_content{
    width: 100%;
    height: 60rpx;
    background: yellow;
    margin: 10rpx 0;
}
.find_box{
    width: 100%;
    height: 100rpx;
}
.find{
    width: 80%;
    height: 60rpx;
    background: #3cc51f;
}
.find_text{
    color: #fff;
}
.start_search_box{
    width: 100%;
    height: 180rpx;
    margin-bottom: 30rpx;
}
.searches{
    width: 100%;
    height: 120rpx;
    border: 2rpx solid #ccc;
}
.search{
    width: 90%;
    height: 60rpx;
    border: 2rpx solid #ccc;
    border-radius: 15px;
}
.search_text{
    background: #9f9;
}
.search_back{
    background: #9f9;
}
.location_box{
    width: 100%;
    height: 50rpx;
    border: 2rpx solid #ccc;
}
.location{
    width: 90%;
    height: 50rpx;
    display: flex;
}

.end_search_box{
    width: 100%;
    height: 120rpx;
    border-bottom: 2rpx solid #ccc;
}
.end_search{
    width: 90%;
    height: 60rpx;
    border-radius: 30rpx;
    border: 2rpx solid #ccc;
}
/*查詢模塊*/
.inquiry_box{
  width: 100%;
  height: auto;
  background: #f99;
}
.inquiry_content{
  width: 90%;
  height: auto;
}
.inquiry_content_list{
  width: 100%;
  height: 60rpx;
}

效果圖,可以查看微信小程序中的圖吧公交


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/18307.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×