zoukankan      html  css  js  c++  java
  • input在数据切换后还可以保持选中状态

    在HTML中:

    <input type="checkbox"  (click)="number($event,item.id)" 
                    [checked]="item.choseStatus ==1" id="in{{item.id}}">
                  <label for="in{{item.id}}"></label>
    在ts/js中:
      this.http
          .post(
            发送请求的相关数据
          )
          .map(res => res.json())
          .subscribe(
            res => {
          //判断是否成功
              if (res.code == 200) { 
          //判断是否有数据
                if (res.data.length > 0) {
                  this.list = res.data;
                  for (var i = 0; i < this.list.length; i++) {
                    // 循环所有已选的课程包括必选课程
                    for (var j = 0; j < this.nub.length; j++) {
                      // 判断所有课程的id是否是已选和必选课程的id
                      if (this.list[i].id == this.nub[j]) {
                        this.list[i].choseStatus = 1; //添加新的属性 说明此数据 已选
                        continue;//结束本次循环
                      }
                    }
                  }
                } else {
                  this.list = [];
                }
              } else {
                this.list = [];
              }
            }
          );
    注:标记颜色部分为重点部分
  • 相关阅读:
    我还没死!!微信公众号——自媒体的营销之路
    网页中嵌入视频
    保存对象到文件中
    bash array
    正则表达式如何验证邮箱
    software testing
    Verification and validation
    bash array
    12 Linux Which Command, Whatis Command, Whereis Command Examples
    如何进行产品路标规划和项目排序?
  • 原文地址:https://www.cnblogs.com/lljun/p/12334476.html
Copyright © 2011-2022 走看看