JS:使用对象传递值

时间:2018-09-23 20:12:23

标签: javascript arrays

class Stages {

  constructor(column_param = {})   {

    this.stages = {};
    let stages_id = IHCM.RandomData.uuid();
    let orderno=1;
    this.columns = {
      "COUNTRY": "",
      "APP_ID": stages_id,
      "STAGEORDER": 1



    };
  }

}



new stages();

如何将阶段订单更新为3?

1 个答案:

答案 0 :(得分:0)

似乎您按了应该在对象变量“ columns”中使用的column_param 因此,如果要将其用作对象的开始参数,它将像这样:

class Stages {
  constructor(column_param = {}) {
    this.stages = {};
    let stages_id = IHCM.RandomData.uuid();
    let orderno = 1;
    this.columns = Object.assign(
      {
        COUNTRY: "",
        APP_ID: stages_id,
        STAGEORDER: 1
      },
      column_param
    );
  }
}

let stages = new Stages({
  STAGEORDER: 3
});

但是,如果它是对象的动态状态,则应将其添加到类方法“ updateOrder”中,然后在其中进行更改

class Stages {
  constructor(column_param = {}) {
    this.stages = {};
    let stages_id = IHCM.RandomData.uuid();
    let orderno = 1;
    this.columns = {
        COUNTRY: "",
        APP_ID: stages_id,
        STAGEORDER: 1
      };
  }

  updateOrder(order) {
    this.columns.STAGEORDER = order;
  }
}

let stages = new Stages();
stages.updateOrder(3);