alibaba / formily

📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3
https://formilyjs.org/
MIT License
11.26k stars 1.46k forks source link

[Feature Request] FormPath 支持数组通配的路径解析与数据操作 #3881

Closed dominicleo closed 1 year ago

dominicleo commented 1 year ago

What problem does this feature solve?

支持数组通配的路径解析与数据操作

What does the proposed API look like?

  1. 路径解析支持数组通配符

    FormPath.parse('foo[].bar'); // segments ['foo', '[]', 'bar'] or ['foo[]', 'bar']
  2. 支持数据操作

    
    const source =  { foo: [{ bar: 1 }, { bar: 2 }, { bar: 3 }] };

FormPath.getIn(source, 'foo[]'); // [ { bar: 1 }, { bar: 2 }, { bar: 3 } ] FormPath.getIn(source, 'foo[].bar'); // [1, 2, 3]

FormPath.setIn(source, 'foo[].bar', 0); // { foo: [{ bar: 0 }, { bar: 0 }, { bar: 0 }] }

FormPath.setIn(undefined, 'foo[].bar', 1); // { foo: [] } FormPath.setIn(undefined, 'foo[].bar', [1, 2, 3]); // { foo: [{ bar: 1 }, { bar: 2 }, { bar: 3 }] }

FormPath.setIn(undefined, '[].bar', 1); // [] FormPath.setIn(undefined, '[].bar', [1, 2, 3]); // [{ bar: 1 }, { bar: 2 }, { bar: 3 }]

FormPath.deleteIn(source, '[].bar'); // { foo: [{}, {}, {}] }