undefinedfix
Sign in

How to change the ID of the province into the corresponding text

user1521306 edited in Fri, 17 Jun 2022

How to change the ID of the province into the corresponding text

4 Replies
villau
commented on Fri, 17 Jun 2022
let obj = {'430100':'南京','430101':'扬州'};
obj['430100'] // '南京'
thexiv
commented on Fri, 17 Jun 2022

No code. Sorry, I can't guess

bstsp
commented on Fri, 17 Jun 2022
  /**
   * 通过ID找到在列表中对应的名字
   * @param {Object} obj
   *  @param obj.dataList 数据列表
   *  @param obj.value    数据的值对应的字段名称   例如 'value'
   *  @param obj.label    数据的说明对应的字段名称 例如 'label'
   *  @param obj.data     当前传入的数据值
   * @return name        返回当前传入值在数组中对应的名字
   */
  getDataName: (obj) => {
    let name = obj.data
    if (Array.isArray(obj.dataList) && obj.dataList.length > 0) {
      for (let i = 0; i < obj.dataList.length; i++) {
        if (obj.dataList[i][obj.value] === obj.data) {
          name = obj.dataList[i][obj.label]
        }
      }
    }
    return name
  }
rortr
commented on Sat, 18 Jun 2022

There is no corresponding ID in option ?

lock This question has been locked and the reply function has been disabled.