收藏
回答

checkbox绑定事件为何无法触发?

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

4 个回答

  • ⅴ
    01-27

    checkbox外面再包一层checkbox-group。事件绑定在checkbox-group上,按文档写

    01-27
    有用 1
    回复
  • 跨商通
    跨商通
    01-27

    bindchanged应该写在checkbox-group上吧?改一下试试。

    01-27
    有用 1
    回复
  • 王新冬
    王新冬
    01-27
    <view class="container">
      <navigation-bar title="代办清单" back="{{false}}" color="black" background="#FFF"></navigation-bar>
      <scroll-view class="task-list" scroll-y="true">
        <block wx:for="{{tasks}}" wx:key="index">
          <view class="task-item {{item.completed ? 'completed' : ''}}" data-index="{{index}}">
            <checkbox bindchange="toggleComplete" class="checkbox" checked="{{item.completed}}" data-index="{{index}}"></checkbox>
            <text bindtap="navigateToDetail" data-task-id="{{item.id}}" class="task-name">{{item.title}}</text>
            <text class="task-date">{{item.create_time}}</text>
          </view>
        </block>
      </scroll-view>
      <view class="footer">
        <view class="input-container">
          <input class="input" placeholder="准备做什么?" bindinput="handleInput" value="{{inputValue}}" />
          <button class="icon-button" bindtap="handleSubmit">
            <image class="icon" src="/assets/send.png" mode="aspectFit" />
          </button>
        </view>
      </view>
    </view>
    



    // pages/list/list.ts

    const app = getApp<IAppOption>();

    Page({

      data: {

        tasks: [],

        openid: '',

        user_id: '',

        inputValue: '',// 用于存储输入框的值

        isLoading: false // 新增一个变量来标记是否正在加载

      },

      

      toggleComplete: function (e) {

        console.log('toggleComplete 被触发', e.detail.value);

        // const index = e.currentTarget.dataset.index;

        // const task = this.data.tasks[index];

        // const newCompleted = e.detail.value; // 直接使用 e.detail.value

        // const newTasks = this.data.tasks.map((t, i) => {

        //   if (i === index) {

        //     return { ...t, completed: newCompleted };

        //   }

        //   return t;

        // });

        // this.setData({ tasks: newTasks });

      },

    })

    还是不行啊,是什么原因,我写的代码太垃圾了吗

    01-27
    有用
    回复
  • 智能回答 智能回答 该问答由AI生成
    01-27
    有用
登录 后发表内容