如何从其他键的可操作数据源中找到另一个键值?

时间:2019-02-01 07:15:24

标签: javascript angularjs reactjs handsontable rhandsontable

我正在使用react-handsontable添加多行,我有一个dropdownSource,在该下拉列表中,我根据名称从列表中填充了名称,如何找到其对应的ID并传入设置数据,以便我可以发送在具有该ID的请求中。

       settings: {
          colHeaders:['Full Name', 'Staff Id','NRIC','Passport' , 'Nationality',  'Position Code',  'Service Code',  'Select Plan'],
          data: [{first_name:"", company_id:"", ic_no: "", passport_no: "", nationality: "",  position_code: "",  service_code: "", subscription_plan_id: ""}],
         columns: [
              { data:"first_name"},
              { data: "company_id"},
              { data: "ic_no"},
              { data:"passport_no"},
              { data: "nationality"},
              { data: "position_code"},
              { data:"service_code"},
              { data: "subscription_plan_id", type: 'dropdown', source:[] },
          ],
          minSpareRows: 0,
          contextMenu: true,
          rowHeaders:true, 
          manualColumnResize: true,
          columnSorting: true, 
          manualRowResize: true, 
          manualRowMove: true,   
          manualColumnMove: true, 
          colWidths: [100, 100, 100,100, 100, 100, 100, 230],
        }

我处于状态,我正在维护设置,从存储更改中,我正在获取图像中所示的列表响应,从图像中我正在填充名称,但是在请求中,我需要填充其对应的subscription_plan_id < / p>

_userStoreChange(type) {
    if (type == 'PlansList') {
        let planslist = UserStore._getAllPlans() || {};
        this.setState({ planslist }, ()=>{
          let plans = this.state.planslist && this.state.planslist.payload;
          let sourceForPackageName = plans.map(el => el.plan_name);
             let columns = this.state.settings.columns.map(function(col){
                    if(col.data === "subscription_plan_id"){
                        col.source = sourceForPackageName;
                    }
                    return col;
             });
            this.refs.hot.hotInstance.updateSettings({columns: columns});

        });
    }

}

可操作组件:

   <HotTable root="hot" ref="hot" settings={this.state.settings} strechH="all" />

在请求中我可以传递plan_name,但是我需要它对应的`subscription_plan_id

Plans List response`

0 个答案:

没有答案