找回密码
 立即注册

扫一扫,访问微社区

查看: 14394|回复: 22

微信小程序学习用demo:中午吃什么?添加选项,随机结果

 火... [复制链接]
发表于 2017-1-11 12:46:00 | 显示全部楼层 |阅读模式





[mw_shl_code=html,true]var app = getApp();

Page({
  data: {
    restaurants : [],
    component : {
      scrollHeight : 0,
      addRestaurantInput : ''
    }
  },
  setComponentParam : function(k,v) {
    var componentParams = this.data.component;
    componentParams[k] = v;
    this.setData({component : componentParams});
  },
  unshiftRestaurant : function(restaurantName) {
    var crl = this.data.restaurants;
    crl.unshift(restaurantName);
    this.setData({restaurants : crl});
    this.setComponentParam('addRestaurantInput','');
    wx.setStorageSync('restaurants', crl);
  },
  onLoad: function () {
    this.setComponentParam('scrollHeight',app.getSystemInfo().windowHeight - 65 - 54 - 8);
    var rStroage = wx.getStorageSync('restaurants') || [];
    this.setData({restaurants : rStroage});

    wx.request({ url : 'https://jazzcai.larkapp.com/appVersion/check',
      success : function(res){
        console.log('ver number:' + res.data.ver + ' des:' + res.data.des);
      }
    });

  },
  onAddRestaurantInputBlur : function (e) {
    this.setComponentParam('addRestaurantInput',e.detail.value);
  },
  onAddRestaurant : function (e) {
    var restaurantName = this.data.component.addRestaurantInput;
    if(!restaurantName || restaurantName == '') {
      wx.showModal({ title : 'Tips', content : '没填你瞎点个毛线啊', showCancel : false });
      return;
    }

    var that = this;
    if(restaurantName.length < 1) {
      wx.showModal({ title : 'Tips', content : '你确定就写这么点?',
        success : function (res) {
          if(!res.confirm) {
            return;
          }
          that.unshiftRestaurant(that.data.component.addRestaurantInput);
        }
      });
    } else {
      this.unshiftRestaurant(this.data.component.addRestaurantInput);
    }
  },
  onRandom : function(e) {
    if(this.data.restaurants.length <= 0) {
      wx.showModal({ title : '错误', content : '餐厅列表为空,请多加一个选项吧!', showCancel : false});
      return;
    }

    var randomIndex = Math.floor(Math.random() * this.data.restaurants.length);
    wx.showModal({ title : '随机结果', content : '"' + this.data.restaurants[randomIndex] + '" 要去么?'});
  },
  onDelete : function(e) {
    var crl = this.data.restaurants;
    crl.splice(e.target.dataset.itemIndex,1);
    this.setData({restaurants:crl});
    wx.setStorageSync('restaurants', crl);
  }
})[/mw_shl_code]



游客,如果您要查看本帖隐藏内容请回复

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

0

主题

3

回帖

23

金钱

新人求带

积分
0
发表于 2017-5-22 22:13:58 | 显示全部楼层
我来看看嘿

0

主题

245

回帖

63

金钱

新人求带

积分
0
发表于 2017-8-21 11:24:23 | 显示全部楼层
感谢分享
回复

使用道具 举报

0

主题

3

回帖

14

金钱

新人求带

积分
0
发表于 2018-2-2 20:35:29 | 显示全部楼层
hao 啥也不说了,感谢楼主分享哇!

0

主题

3

回帖

254

金钱

新人求带

积分
0
发表于 2018-2-4 20:26:55 | 显示全部楼层
学习一下
回复

使用道具 举报

0

主题

25

回帖

30

金钱

新人求带

积分
0
发表于 2018-5-30 11:53:33 | 显示全部楼层
多谢分享
回复

使用道具 举报

0

主题

4

回帖

14

金钱

新人求带

积分
0
发表于 2018-7-20 16:36:10 | 显示全部楼层
谢谢分享
回复

使用道具 举报

0

主题

4

回帖

23

金钱

新人求带

积分
0
发表于 2018-12-10 11:25:40 来自手机 | 显示全部楼层
需要服务器吗?谢谢

0

主题

1

回帖

12

金钱

新人求带

积分
0
发表于 2019-11-29 22:23:42 | 显示全部楼层
谢谢分享
回复

使用道具 举报

0

主题

3

回帖

30

金钱

新人求带

积分
0
发表于 2019-12-15 18:06:28 | 显示全部楼层
看起来挺不错的
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|微信小程序开发|教程|文档|资源汇总_即速论坛 ( 粤ICP备14097199号-1  

GMT+8, 2024-3-29 18:59 , Processed in 0.127166 second(s), 31 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表