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

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

Closed dominicleo closed 1 year ago

dominicleo commented 1 year ago
  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: [{}, {}, {}] }

github-actions[bot] commented 1 year ago

Hello @dominicleo, your issue has been closed because it does not conform to our issue requirements. Please use the Issue Helper to create an issue, thank you! 你好 @dominicleo,为了能够进行高效沟通,我们对 issue 有一定的格式要求,你的 issue 因为不符合要求而被自动关闭。你可以通过 issue 助手 来创建 issue 以方便我们定位错误。谢谢配合!