Function arr2select

  • 转化为 Select 数据,至少有 label/value/key 字段。

    Parameters

    • arr: any[]

      数组

    • options: {
          key?: string;
          label?: string;
          value: string;
      }

      配置 { label?: 'label', value: 'value', key?: 'key' }

      • Optionalkey?: string
      • Optionallabel?: string
      • value: string

    Returns any[]

    arr2select([{ id: 1, name: 'A' }, { id: 2, name: 'B' }], { label: 'name', value: 'id' });
    /// [{ label: 'A', value: 1, key: 'selectKey-Random1' }, { label: 'B', value: 2, key: 'selectKey-Random2' }]
    arr2select([{ id: 1, name: 'A' }, { id: 2, name: 'B' }], { value: 'id', key: 'UNDEFINED' });
    /// [{ label: 1, value: 1, key: 1 }, { label: 2, value: 2, key: 2 }]
    arr2select([{ data: { id: 1, name: 'A' }, key: 'test1' }, { data: { id: 2, name: 'B' }, key: 'test2' }], { value: 'data.id', key: 'key', label: 'data.name' });
    /// [{ value: 1, label: "A", key: "test1" }, { value: 2, label: "B", key: "test2" }]