美文网首页
小程序知识点

小程序知识点

作者: 拾钱运 | 来源:发表于2020-02-08 21:50 被阅读0次

    1.修改data中的数组对象中的某一项

    方法1:

    data: {
        cartGoods:[
          {
            id:"1",
            checked:false,
          },
          {
            id:"2",
            checked:false
          },
          {
            id:"3",
            checked:false
          }
        ]
      },
    checkedItem:function(e){
        console.log(e.currentTarget.dataset.id)
    //点击帮定的元素的id
                                  var  index=e.currentTarget.dataset.id-1
        console.log(index)
    //data定义的数组对象
                                  var obj='cartGoods['+index+'].checked'
        console.log(obj)
         this.setData({
              [obj]:false
            })
        }
    

    方法2:

    checkedItem:function(e){
        console.log(e.currentTarget.dataset.id)
    //点击帮定的元素的id
                                  var  index=e.currentTarget.dataset.id-1
        console.log(index)
    //data定义的数组对象
                                  this.data.cartGoods[index].checked=false
            this.setData({
              cartGoods:this.data.cartGoods
            })
        }
    

    2.小程序中监听数组对象(数据)

    推送门:https://blog.csdn.net/xuyangxinlei/article/details/81408200

    3.调用小程序中自定义组件的方法

      onReady: function () {
        this.tabbar=this.selectComponent('#tabbar')
      },
      //然后在需要调用自定义方法的地方直接调用即可
    this.tabbar.show()
    

    自定义中的方法 show()


    image.png

    自定义组件的引用和使用


    image.png
    image.png

    相关文章

      网友评论

          本文标题:小程序知识点

          本文链接:https://www.haomeiwen.com/subject/agjwxhtx.html