【angular】多个实体的嵌套

#前言


最近在做项目的时候发现一个实体不能够满足项目的需求了,需要多个实体嵌套在一起,由于自己原来做的都是一些简单的操作,突然要实现多个实体的嵌套,这可是有点难住我了,不过成长都是在探索中,下面就让我们一起来看看如何实现吧。
#叙述

实体的嵌套

所谓实体的嵌套,就是多个实体嵌套在一起,一个实体中实例化另外的一个实体。

实体的实例化
export class AddPage {
  leftPage = new LeftPage();   //左
}

export class LeftPage {
  processId: string;
  createdId: string;
  parentPageModel = new ParentPageModel();   // 一级页签
}

// 一级页签
export class ParentPageModel {
  commonPageMap = new Array<CommonPageMap>();  //通用页面名称实体集合
  pageMap = new Array<PageMap>();  //自定义页面名称实体集合
  pageModelLevel: string; //页签层级
  screenType: string;   //页面位置
}

// 一级页签中自定义页面名称的实体,id不用前端传递
export class PageMap {
  id: string;
  name: string;
  type: string;
  des: string;

}

// 一级页签中通用页面名称的实体
export class CommonPageMap {
  id: string;
  name: string;
  type: string;
  des: string;

}
实体应用
 //大model
  public addPageModel: AddPage = new AddPage(); 

  // 一级页签通用页面名称集合-接收控件获取数据  
  public commonPageNameMap = new Array();

  // 一级页签通用名称实体  
  public pageMap = new PageMap();

  // 一级页签自定义页面名称实体
  public commonPageMap = new CommonPageMap();
  @Input()
  processId: string;
  submit() {
    /**
     *单屏单级:在addPageModel中仅有parentPageModel有值,其余为空
     */
    // ---------------------流程ID和创建人-------------------------------------------------------------
    this.addPageModel.leftPage.createdId = '张张';
    // 预览id
    this.addPageModel.leftPage.processId = this.processId;

    console.log('预览ID对吗?');

    console.log(this.processId);

    /**
     *-------------------自定义:描述、层级、名称、类型,名称为一个数组,数据中仅包含名称,名称对应的ID由后端自行生成
     */
    // --------------------自定义页面----------------------------------------------------------
    // this.addPageModel.leftPage.parentPageModel.screenType = '左';
    // this.addPageModel.leftPage.parentPageModel.pageModelLevel = '一级';
    // 一级中自定义页面名称的获取
    this._submitForm().forEach(
      el => {       
        this.addPageModel.leftPage.parentPageModel.pageMap.push({ id: null, name: el, type: '自定义页面', des: this.pageMap.des });
      });
    console.log('自定义model:' && this.addPageModel.leftPage.parentPageModel.pageMap);

    // 通用页面名称的获取
    this.commonPageNameMap.forEach(
      item => {
        this.addPageModel.leftPage.parentPageModel.commonPageMap.push({ id: item.id, name: item.modelName, type: '通用页面', des: this.commonPageMap.des });
      }
    )
    console.log('通用model:' && this.addPageModel.leftPage.parentPageModel.commonPageMap);
    
    let body = JSON.stringify(this.addPageModel);
    console.log('最后添加的流程节点与页面绑定的model——' && this.addPageModel);

    let url = 'work/ProcessPageConfigController/addPageModel';
    this.http.post(url, body).subscribe(
      res => {

        if (res.json().code == '20000') {

          console.log(res.json().msg);
          this.successInfo = '流程节点与页签配置信息提交成功';
          this.success()

        } else {
          this.errorInfo = '流程节点与页签配置信息提交失败';
          this.error();
        }
      }
    )
  }

 // 一级自定义页面名称集合
  public addSubPage = new Array();
  _submitForm() {
    console.log('第一次');
    console.log(this.validateForm.controls)
    for (const i in this.validateForm.controls) {
      this.validateForm.controls[i].markAsDirty();
      this.addSubPage.push(this.validateForm.controls[i].value);
    }
    console.log('自定义页面名称集合:' && this.addSubPage);
    return this.addSubPage;
  }


结果展现

这里写图片描述
#小结
原理很简单,重要的是要知道如何去实现。
感谢您的阅读~

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hi-Sunshine

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值