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 = [];
              }
            }
          );
    注:标记颜色部分为重点部分
  • 相关阅读:
    .html(),.text()和.val()的差异总结:
    获取或设置checkbox radio select的值
    sublime 搜索时忽略文件夹
    转载------一小时包教会 —— webpack 入门指南
    转载--git教程
    转载--网站数据统计分析中的日志收集原理及其实现
    devexpress 安装及破解
    基于socket的客户端和服务端聊天简单使用 附Demo
    Ajax技术原理小结
    oracle 资源学习汇总
  • 原文地址:https://www.cnblogs.com/lljun/p/12334476.html
Copyright © 2011-2022 走看看