收藏
评论

JavaScript函数与拓展官方

JavaScript进阶内容学习:函数与小程序特有的JS。

课程最终代码,点此领取:https://share.weiyun.com/5Kb7U6O


最后一次编辑于  2021-11-26
赞 48
收藏

27 个评论

  • 归真
    归真
    2022-01-06

    感谢老师分享

    2022-01-06
    赞同
    回复
  • 程天鹏财务软件
    程天鹏财务软件
    2021-12-18

    我也是小白,看了第二遍还是似懂非懂的。坚持直到熟练。

    2021-12-18
    赞同
    回复
  • 散养猪与走地鸡
    散养猪与走地鸡
    2021-12-15

    代码发不出来,只能试试发图片。

    完美解决按钮点击后一片空白的问题。不用复制声明一遍list,如果你有动态数据库,不可能每次都去复制一遍。

    2021-12-15
    赞同
    回复 2
    • 孙程
      孙程
      2022-01-24
      “全部”你不用再写一遍,和免费付费一样,给onFilter穿个参数就行了。
         onAll: function () {
          this.onFilter('all')
        },
        onFilter: function (type) {
          let newData = [];
          let data = this.data.list;
          let i = 0;
          let len = data.length;
          for (; i < len; i++) {
            if(type == 'all'){
               if (data[i].price != -1){
                  newData.push(data[i]);
                }
             }else if(type == 'cost'){
                if (data[i].price > 0){
                  newData.push(data[i]);
                }
            }else{
              if (data[i].price == 0){
                newData.push(data[i]);
              }
          }
          }
          this.setData({
            list1: newData
          })
        }
      2022-01-24
      回复
    • 孙程
      孙程
      2022-01-24
      还有onLoad里边不用写for,本来就是list里有什么无条件给list1,所以我觉得直接给就行了。
        onLoad: function () {
          let data = this.data.list; 
          this.setData({
            list1:data
          })
        },
      目前我测试没问题,我也小白,乱七八糟学了一堆,不对的地方请指教
      2022-01-24
      回复
  • 文
    2021-09-27

    或者定义一个全局变量,保存所有的课程:

    var courses = [{

        price: 0,

        name: '人人都会小程序',

        coverPath: '../../images/cover.png'

    },

    {

        price: 149,

        name: '人人都会小程序实战',

        coverPath: '../../images/cover.png'

    },

    {

        price: 249,

        name: '人人都会小程序实战2',

        coverPath: '../../images/cover.png'

    }]


    然后再onFilter 中赋值:let data = courses;

    全部js:

    var courses = [{

        price: 0,

        name: '人人都会小程序',

        coverPath: '../../images/cover.png'

    },

    {

        price: 149,

        name: '人人都会小程序实战',

        coverPath: '../../images/cover.png'

    },

    {

        price: 249,

        name: '人人都会小程序实战2',

        coverPath: '../../images/cover.png'

    }]


    Page({

        data: {

            course_list: [

                {

                    price: 0,

                    name: '人人都会小程序',

                    coverPath: '../../images/cover.png'

                },

                {

                    price: 149,

                    name: '人人都会小程序实战',

                    coverPath: '../../images/cover.png'

                },

                {

                    price: 249,

                    name: '人人都会小程序实战2',

                    coverPath: '../../images/cover.png'

                }

            ],

        },


        onFree: function () {

            this.onFilter()

        },


        // 函数

        onCost: function () {

            this.onFilter('cost')

        },


        onFilter: function (type) {

            let data = courses;

            let newData = [];

            let i = 0;


            for (; i < data.length; i++) {

                if (type == 'cost') {

                    if (data[i].price > 0) {

                        newData.push(data[i]);

                    }

                } else {

                    if (data[i].price == 0) {

                        newData.push(data[i]);

                    }

                }

            }


            this.setData({

                course_list: newData

            })

        }

    })

    2021-09-27
    赞同
    回复
  • 准时不早退的EVA
    准时不早退的EVA
    2021-09-26

    老师讲的真的很好

    2021-09-26
    赞同
    回复
  • A👄磨人精👸yoga👈
    A👄磨人精👸yoga👈
    2021-08-27

    遇到了相同的问题,按照老师的教程走的,编译之后点击【付费】可以出来付费内容,再点击免费的时候就空白了,然后再重新编译之后点击【免费】可以出来免费内容,就是不能再点了,js方法都走了,为什么页面会空白吗,请问这js代码里还需要怎么做吗,才能做出来【付费】和【免费】可以相互的切换相应的信息呢

    2021-08-27
    赞同
    回复
  • less
    less
    2021-03-15

    hahhaha,jero老师,2019年寒假学过

    2021-03-15
    赞同
    回复

正在加载...

登录 后发表内容
课程标签