Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

项目中依赖的lodash.merge方法有问题,导致内部调用的setByPath方法未能正确更新数据 #4496

Closed
shockingsrose opened this issue Nov 7, 2024 · 2 comments

Comments

@shockingsrose
Copy link

Describe the bug

参考这个复现链接lodash playground
image

这个数组的长度应该是1

Your Example Website or App

https://playcode.io/2131003

Steps to Reproduce the Bug or Issue

直接查看上述链接的console日志即可

Expected behavior

希望能修复一下merge方法不依赖lodash

Screenshots or Videos

No response

Platform

  • OS: [macOS]
  • Browser: [Arc]
  • Version: [2.18.1]

Additional context

No response

@x6-bot
Copy link
Contributor

x6-bot bot commented Nov 7, 2024

👋 @shockingsrose

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it.
To help make it easier for us to investigate your issue, please follow the contributing guidelines.
We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

@shockingsrose
Copy link
Author

问题解决了,这里是我理解有误,lodash.merge在处理数组时,如果数组长度变化了,默认会做合并而不是替换
代码示例如下:

const o1 = { list: [{ a: 1 }, { a: 2 }] };
const o2 = { list: [{ a: 3 }] };

const rlt1 = _.merge(o1, o2);
console.log(rlt1) // {"list":[{"a":3},{"a":2}]}

我实际上希望的结果是 { list: [{ a: 3 }] }

最终解决方案:调用setPortProp增加了{ rewrite: true }配置

另外文档上并没有写rewrite配置,我是在源码里看到的,建议在官方文档里添加一下这个配置及对应的含义

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant