收藏
回答

为什么this.setData不能改变页面状态了?

WXML:

 <block wx:for="{{cateItems[curIndex].children}}wx:key="{{index}}">

          <view style="position:relative">

            <view class="nav_right_items">

              <text>{{item.name}}</text>

              <text style="color:red">¥{{item.price}}/斤</text>

            </view>

            <view class="counts">

              <text class="reduce {{status}}bindtap="reducedata-index="{{index}}">-</text>

              <input class="numbervalue="{{item.num}}data-index="{{index}}bindinput="bindValue"></input>

              <text class="addbindtap="adddata-index="{{index}}">+</text>

            </view>

          </view>

        </block>


JS:

data: {

    arr: ["蔬菜","调味品","米类","面类","油类","干果类","水产类","肉类","杂粮类","冻货类","酒水类","芽菜类","烫菜类"],

    index: 1,

    currentTab: 0,

    cateItems:[

        {

          cate_id:1,

          cate_name:'根茎类',

          children: [

            { 

              child_id: 1, 

              name: '(皱皮)辣椒',

              price: 6,

              num:0

            }, 

            { 

              child_id: 2, 

              name: '黄皮洋葱',

              price: 1.5,

              num:0

            },

            { 

              child_id: 3, 

              name: '苦菊',

              price: 3.5,

              num:0 

            },

            { 

              child_id: 4, 

              name: '蛋皮',

              price: 6,

              num:0

            }

          ]

        },

       

      curNav:1,

      curIndex:0,

      stasus:"disabled"

  },


add:function(e){

    let index = e.currentTarget.dataset.index;

    var curIndex = this.data.curIndex;

    var children = this.data.cateItems[curIndex].children[index];

    console.log(children)

    var num = children.num;

    var status = num<1?"disabled":"normal";

    num = num + 1;

    console.log(num)

    children.num = num;

    this.setData({

      num:num,

      status:status

    })

    console.log(children)

    console.log(num)

  },

我this.setData里面写的不对吗

回答关注问题邀请回答
收藏

2 个回答

  • 付
    10-13

    列表二级数据监听重叠! 嵌套的二级数据 取出做为临时数据 新增插入到列表中。

    10-13
    有用
    回复
  • จุ๊บ
    จุ๊บ
    10-11

    只看见了status 这个变量,没有看到 num 这个变量啊。你先看下status 这个变量是否改变呢?

    10-11
    有用
    回复
登录 后发表内容
问题标签