用户
 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,登录网站

2518

主题

7246

帖子

2万

积分

版主

Rank: 7Rank: 7Rank: 7

积分
25300
2017-1-6 21:39:38 天下雪原创达人 造轮子 版主 楼主 822304
12312.gif

代码示例:
[AppleScript] 纯文本查看 复制代码
// pages/destination/destination.js
var tempArr = [];
Page({
  data:{
      winHeight: 0,
      winWidth:0,
      searchHeight:0,
      margin:0,
      currentIndex:0, 
      citys:[],
      history:[],
      destinations:[
                  {"destination":"热门",
                  "id":"0"},
                  {"destination":"国内",
                  "id":"1"},
                  {"destination":"东南亚",
                  "id":"2" },
                  {"destination":"日韩",
                  "id":"3" },
                  {"destination":"海岛",
                  "id":"4" },
                  {"destination":"港澳台",
                  "id":"5" },
                  {"destination":"欧洲",
                  "id":"6" },
                  {"destination":"美洲",
                  "id":"7" },
                  {"destination":"澳洲",
                  "id":"8" },
                  {"destination":"中东非",
                  "id":"8" },
                   {"destination":"热门",
                  "id":"1" },
                  {"destination":"热门",
                  "id":"0"},
                  {"destination":"国内",
                  "id":"1"},
                  {"destination":"东南亚",
                  "id":"2" },
                  {"destination":"日韩",
                  "id":"3" },
                  {"destination":"海岛",
                  "id":"4" },
                  {"destination":"港澳台",
                  "id":"5" },
                  {"destination":"欧洲",
                  "id":"6" },
                  {"destination":"美洲",
                  "id":"7" },
                  {"destination":"澳洲",
                  "id":"8" },
                  {"destination":"中东非",
                  "id":"8" }
                  ],

        cityList:[
          [{"initial":"热门国际","items":["纽约","加拿大","泰国","韩国","日本","迪拜"]},{"initial":"热门国内","items":["北京","三亚","香港"]},{"initial":"热门国内","items":["北京","三亚","香港"]},{"initial":"热门国内","items":["北京","三亚","香港"]},{"initial":"热门国内","items":["北京","三亚","香港"]},{"initial":"热门国内","items":["北京","三亚","香港"]},{"initial":"热门国际","items":["纽约","加拿大","泰国","韩国","日本","迪拜"]},{"initial":"热门国际","items":["纽约","加拿大","泰国","韩国","日本","迪拜"]},{"initial":"热门国际","items":["纽约","加拿大","泰国","韩国","日本","迪拜"]},{"initial":"热门国际","items":["纽约","加拿大","泰国","韩国","日本","迪拜"]}],
    [{"initial":"","items":["北京","三亚","香港"]}],
     [{"initial":"","items":["泰国","新加坡","吉隆坡"]}],
     [{"initial":"","items":["韩国","日本","东京"]}],
     [{"initial":"","items":["济州岛","海盗","塞班"]}],     [{"initial":"","items":["澳门","台北","香港"]}],
        ]
  },
  // 点击事件
  switchTab:function(e){
    console.log(e);
    var id = e.currentTarget.dataset.id;

    // 造假数据,右侧的
    console.log(typeof id);
    var citys = this.data.cityList[id];
    this.setData({
      currentIndex:id,
      citys:citys
    });
  },
  cityClick:function(e){
    tempArr.splice(0,0,e.currentTarget.dataset.city);
    this.setData({
      history:this.historyUnique(tempArr),
    });
  },
  // 历史记录去重
  historyUnique:function(arr){
    var newArr = [];
    for(var i in arr){
      if(newArr.indexOf(arr[i])==-1){
        newArr.push(arr[i]);
      }
    }
    return newArr;
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
     // 获取屏幕的高度
    var sysInfo = wx.getSystemInfoSync();
    var winHeight = sysInfo.windowHeight;
    var winWidth = sysInfo.windowWidth;
     // 先将rpx 转换为 px
    var searchH = Math.floor(164*(winWidth/750));
    var margin = Math.floor(20*(winWidth/750));
      // 造假数据,右侧的
    var citys = this.data.cityList[this.data.currentIndex];
    this.setData({
      winHeight:winHeight,
      winWidth:winWidth,
      searchHeight:searchH,
      margin:margin,
      citys:citys
    });
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  }
})


项目地址及下载:
https://github.com/Nsir15/citySwitch
citySwitch-master.zip (18.31 KB, 下载次数: 103)
有问题请在本站内搜索相应关键词,假如无法解决请在综合交流区内发帖咨询,发帖时请提供详细的问题描述、相关图片及代码。
学习了
厉害了
正好学习,多谢楼主
项目地址过来看看
2017-1-8 19:07:18 abc001 诠释者
6#
谢谢
xuex
shshishisasd
mark
haozan haozan
学习了
来看看
xuexi
你好
发新帖
您需要登录后才可以回帖 登录 | 立即注册