微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Angular4_table中的checkbox 全选,按钮启用禁用

这客户比较特殊,啥都得选中行能选中checkBox,并且未选中时按钮需要禁用。 可以理解


代码比较简单,table代码

<div class="modal-header">
          <p class="modal-title">logout Warnning</p>
        </div>
        <div class="modal-body">
                <p>Your have working order(s). if you logout the order(s) will be returned to the Pick Queue and all unconfirmed handling units will remove. Do you want to continue logout? </p>
            <table class="table">
                <thead>
                  <tr>
                    <th>
                        <input type="checkBox" name="checkedAll" [checked]="isAllChecked()" (change)="checkAll($event)">
                    </th>
                    <th>Phase Code</th>
                    <th>Delivery</th>
                    <th>Product</th>
                  </tr>
                </thead>
                <tbody>
                  <tr *ngFor="let task of this.releaseTasks.releaseTaskDetails index as i;"(click)="onModalSelectedRows(task)"
>
                    <td>
                        <input type="checkBox" [(ngModel)]="task.isChecked" name="checkedTask{{i}}" #checkedTask="ngModel"/>
                    </td>
                    <td>
                        {{task.phaseCode}}
                    </td>
                    <td>
                        {{task.saP_DeliveryOrder_ID}}
                    </td>
                    <td>
                        {{task.saP_ProductOrder_ID|removeLeadingZeros}}
                    </td>
                  </tr>
                </tbody>
              </table>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" (click)="c('Yes')" [disabled]="!canRelease">Release and logout</button>
          <button type="button" class="btn btn-primary" (click)="c('No')">logout only</button>
        </div>

后台ts代码

 
 
checkAll(ev: any) {
this.releaseTasks.releaseTaskDetails.forEach((x:any) => x.isChecked = ev.target.checked)
}
isAllChecked() {
if(this.releaseTasks.releaseTaskDetails.length > 0 ){
return this.canRelease = this.releaseTasks.releaseTaskDetails.every((_:any) => _.isChecked);
}
return false;
}
onModalSelectedRows(task : any) {
task. isChecked = ! task. isChecked;
let len = 0;
this. releaseTasks. releaseTaskDetails. forEach((item : any) => {
if( item. isChecked) {
len ++;
}
});
if( len === 0) {
this. canRelease = false;
} else{
this. canRelease = true;
}
}

后台viewmodel代码

public class ReleaseTaskviewmodel {
        public string Operator_ID {get; set;}
        public int OperatorActivityId {get; set;}
        public int DeliveryOrder_ID {get; set;}
        public int Productionorder_ID {get; set;}
        public string SAP_DeliveryOrder_ID {get; set;}
        public string SAP_ProductOrder_ID {get; set;}
        public string PhaseCode { get; set; }
        public bool isChecked { get; set; }
        public bool isPersistent { get; set; }
        public int OrderId{get;set;}
    }
    public class ReleaseTask{
        public ReleaseTask() {
            this.ReleaseTaskDetails = new List<ReleaseTaskviewmodel>();
        }
        public List<ReleaseTaskviewmodel> ReleaseTaskDetails {get;set;}
    }

Controller 代码

var activityQuery = from op in _context.OperatorActivities
                                where op.Operator_ID == userName && !op.IsComplete && !op.IsReleased && !op.IsException 
                                select op;
            
            ReleaseTask relesaseTask = new ReleaseTask();

            if(activityQuery.Any()){
                foreach (var activity in activityQuery)
                {
                    ReleaseTaskviewmodel taskDetail = new ReleaseTaskviewmodel();
                    taskDetail.SAP_DeliveryOrder_ID = getorderById(activity.DeliveryOrder_ID);
                    taskDetail.SAP_ProductOrder_ID = getProductOrderById(activity.Productionorder_ID);
                    taskDetail.PhaseCode = activity.ActivityCode;
                    taskDetail.isChecked = true;
                    taskDetail.OperatorActivityId = activity.OperatorActivity_ID;
                    taskDetail.DeliveryOrder_ID = activity.DeliveryOrder_ID;
                    taskDetail.Productionorder_ID = activity.Productionorder_ID;
                    taskDetail.Operator_ID = activity.Operator_ID;
                    taskDetail.OrderId = activity.ActivityCode == "MAKE" ? activity.Productionorder_ID : activity.DeliveryOrder_ID;
                    taskDetail.isPersistent = isPersistent(activity.Productionorder_ID);
                    if(!taskDetail.isPersistent) {
                        relesaseTask.ReleaseTaskDetails.Add(taskDetail);
                    }
                }
            }
            return(Ok(new { success = true,data = relesaseTask}));
代码还是比较臭,还是得加强啊。

原文地址:https://www.jb51.cc/angularjs/144510.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐