收藏
回答

server.getJSON这个函数的怎么一回事!

问题模块 框架类型 问题类型 终端类型 微信版本 基础库版本
框架 小程序 需求 工具 6.5.3 2.5.2
    onLoad: function () {
        var self = this;
        wx.getLocation({
            type: 'gcj02',
            success: function (res) {
                var latitude = res.latitude;
                var longitude = res.longitude;
                server.getJSON('/waimai/api/location.php', {
                    latitude: latitude,
                    longitude: longitude
                }, function (res) {
                    console.log(res)
                    if (res.data.status != -1) {
                        self.setData({
                            address: res.data.result.address_component.street_number
                        });
                    } else {
                        self.setData({
                            address: '定位失败'
                        });
                    }
                });
            }
        })
    },
    onShow: function () {
    },
    onScroll: function (e) {
        if (e.detail.scrollTop > 100 && !this.data.scrollDown) {
            this.setData({
                scrollDown: true
            });
        } else if (e.detail.scrollTop < 100 && this.data.scrollDown) {
            this.setData({
                scrollDown: false
            });
        }
    },
    tapSearch: function () {
        wx.navigateTo({url: 'search'});
    },
    toNearby: function () {
        var self = this;
        self.setData({
            scrollIntoView: 'nearby'
        });
        self.setData({
            scrollIntoView: null
        });
    },
    tapFilter: function (e) {
        switch (e.target.dataset.id) {
            case '1':
                this.data.shops.sort(function (a, b) {
                    return a.id > b.id;
                });
                break;
            case '2':
                this.data.shops.sort(function (a, b) {
                    return a.sales < b.sales;
                });
                break;
            case '3':
                this.data.shops.sort(function (a, b) {
                    return a.distance > b.distance;
                });
                break;
        }
        this.setData({
            filterId: e.target.dataset.id,
            shops: this.data.shops
        });
    },
    tapBanner: function (e) {
        var name = this.data.banners[e.target.dataset.id].name;
        wx.showModal({
            title: '提示',
            content: '您点击了“' + name + '”活动链接,活动页面暂未完成!',
            showCancel: false
        });
    }
});


最后一次编辑于  02-06  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏投诉关注问题回答