Giter VIP home page Giter VIP logo

Comments (2)

lumdzeehol avatar lumdzeehol commented on June 6, 2024

这个问题发生在 ArrayField 往数组中间insert的时候,向数组尾部添加不会触发该问题。

该 issue 中的 case 在 ArrayField 执行 spliceArrayState 方法的时候,分别发生以下情况:

  • 第一次 copy, 尾部插入,元素不需要 move,插入的 field 对应 address 由 Form.createField() 生成。此时Path 对象由 FormPath.parse('array').concat(1)生成,因此segment的值为 ['array', 1]
  • 第二次 copy, 中间插入,触发 moveIndex 方法生成 fieldPatch。fieldPatch 使用 identifier 作为 address ,identifier为字符串 "array.2",丢失了数组下标的类型,因此 segment 的值为['array', '2']

const moveIndex = (identifier: string) => {
if (offset === 0) return identifier
const preStr = identifier.substring(0, addrLength)
const afterStr = identifier.substring(addrLength)
const number = afterStr.match(NumberIndexReg)?.[1]
if (number === undefined) return identifier
const index = Number(number) + offset
return `${preStr}${afterStr.replace(/^\.\d+/, `.${index}`)}`
}

@janryWang 我尝试将 moveIndex 的返回改成 FormPath.parse(preStr).concat(index) , 但是会破坏 interface INodePatch 的声明,INodePath 中的address 都是字符串类型,白总看看这个能改成Pattern 类型吗,或者还是考虑别的解决办法?

from formily.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.