WeChat Mini Programs asks a question of multiple choices.

problem description

see the following figure.
check to change the color, up to 7. There will be a prompt after clicking on the 8th. And more than 7 clicks do not change the color.
if I click on the previously selected color, I can remove the selected color, and I can also click on something else that is not selected.

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

<view class="habit_taglist">
        <view class="{{item.active?"active-tag":""}} habit_tag fl" wx:for="{{tags}}"  bindtap="tagTap" data-key="{{index}}" wx:key="index"   data-test="4">{{item.habitName}}</view>

< / view >



tagTap: function (e) {
    this.setData({
      habittags: []
    })
    var index = e.currentTarget.dataset.key;
    console.log(this.data.tags)
    for (var i = 0; i < this.data.tags.length; iPP) {
      if (this.data.tags[i].active) {
        this.data.habittags.push(
          {
            habitId: this.data.tags[i].zid,
            babyId: this.data.babyId,
            groupId: getApp().globalData.groupId,
            habitDay: this.data.tags[i].habitDay
          })
      }
    }
    this.setData({
      habittags: this.data.habittags
    })
    console.log(this.data.habittags)
    if (this.data.habittags.length >= 7) {
      if (this.data.tags[index].active) {
        this.data.tags[index].active = !this.data.tags[index].active
        this.setData({
          tags: this.data.tags
        });
      } else {
        var test = e.target.dataset.test;
        if (test == 4) {
          getApp().feedbackApi.showToast({
            title: "7",
            mask: false
          })
        }
      }
    } else {
      this.data.tags[index].active = !this.data.tags[index].active
      this.setData({
        tags: this.data.tags
      });
    }
  },


what result do you expect? What is the error message actually seen?

the above has bug for advice


< H2 > wxml file < / H2 >
<view class="habit_taglist">
  <block wx:for="{{tags}}" wx:key="index" >
    <view 
      class="{{item.active?'active':'noactive'}}" 
      bindtap="tagTap" 
      data-content="{{item}}"
      data-index="{{index}}"
      >{{item.habitName}}</view>
  </block>  
</view>

wxss file


.habit_taglist{
  display: flex;
  flex-wrap: wrap;
}
.noactive{
  width: 100rpx;
  height: 100rpx;
  border: 1rpx solid -sharp333;
  display: flex;
  justify-content: center;
  align-items: center;
}
.active{
  background-color: -sharpf00;
  width: 100rpx;
  height: 100rpx;
  border: 1rpx solid -sharpf00;
  display: flex;
  justify-content: center;
  align-items: center;
}
< H2 > js file < / H2 >
const Page = require('../../utils/ald-stat.js').Page;
Page({
  data: {
    tags: [{ habitName: '1' }, { habitName: '2' },
      { habitName: '3' }, { habitName: '4' },
      { habitName: '5' }, { habitName: '6' },
      { habitName: '7' }, { habitName: '8' },
      { habitName: '9' }, { habitName: '10' },
      { habitName: '11' }, { habitName: '12' },
      { habitName: '13' }, { habitName: '14' },
      { habitName: '15' }, { habitName: '16' },
      { habitName: '17' }, { habitName: '18' }],
    tempTags:[],
    count:0
  },

  onLoad: function(options) {
  },
 
  tagTap: function (e) {
    let count = this.data.count
    const temoName = e.currentTarget.dataset.content.habitName
    const ii = e.currentTarget.dataset.index
    let temp = this.data.tags;
    temp.map((v, index) => {
      if (ii == index) {
        if(v.active){
          --count
          v.active = !v.active
        }else{
          if(count+1>7){
            return ;
          }else{
            PPcount
            v.active = !v.active
          }
        }
      }
    })
    this.setData({
      tags: temp,
      count: count
    })
  }
})
< H2 > the result is shown in the figure < / H2 >

WX20181201-183020%402x.png

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb744c-2643.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb744c-2643.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?