* 构造 items 属性,同时构造 maps 属性
()
| 160 | * 构造 items 属性,同时构造 maps 属性 |
| 161 | */ |
| 162 | private get items(): IProp[] | null { |
| 163 | if (this._items) return this._items; |
| 164 | return runInAction(() => { |
| 165 | let items: IProp[] | null = null; |
| 166 | if (this._type === 'list') { |
| 167 | const maps = new Map<string, IProp>(); |
| 168 | const data = this._value; |
| 169 | data.forEach((item: any, idx: number) => { |
| 170 | items = items || []; |
| 171 | let prop; |
| 172 | if (this._maps?.has(idx.toString())) { |
| 173 | prop = this._maps.get(idx.toString())!; |
| 174 | prop.setValue(item); |
| 175 | } else { |
| 176 | prop = new Prop(this, item, idx); |
| 177 | } |
| 178 | maps.set(idx.toString(), prop); |
| 179 | items.push(prop); |
| 180 | }); |
| 181 | this._maps = maps; |
| 182 | } else if (this._type === 'map') { |
| 183 | const data = this._value; |
| 184 | const maps = new Map<string, IProp>(); |
| 185 | const keys = Object.keys(data); |
| 186 | for (const key of keys) { |
| 187 | let prop: IProp; |
| 188 | if (this._maps?.has(key)) { |
| 189 | prop = this._maps.get(key)!; |
| 190 | prop.setValue(data[key]); |
| 191 | } else { |
| 192 | prop = new Prop(this, data[key], key); |
| 193 | } |
| 194 | items = items || []; |
| 195 | items.push(prop); |
| 196 | maps.set(key, prop); |
| 197 | } |
| 198 | this._maps = maps; |
| 199 | } else { |
| 200 | items = null; |
| 201 | this._maps = null; |
| 202 | } |
| 203 | this._items = items; |
| 204 | return this._items; |
| 205 | }); |
| 206 | } |
| 207 | |
| 208 | @computed private get maps(): Map<string | number, IProp> | null { |
| 209 | if (!this.items) { |