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

[Field] 开启parseName 后 setValues 无法对深层次数据赋值 #497

Closed
Mrluobo opened this issue Mar 25, 2019 · 6 comments
Closed
Assignees

Comments

@Mrluobo
Copy link

Mrluobo commented Mar 25, 2019

related: https://codepen.io/anon/pen/pYbVrE#anon-login

@bindoon
Copy link
Member

bindoon commented Mar 26, 2019

我已经想到一种解决方法,但是感觉比较hack。 setValues 的时候先把数据缓存下来,等真正init的时候再去处理赋值,getValues 的时候跟着缓存数据去做merge 。
但是要处理的带来的几个问题就是,1. 不清楚何时所有组件init完成,2. 要解决数据赋值后再清空的情况,避免再次赋值 3. 可能要解决数组错位问题

@bindoon
Copy link
Member

bindoon commented Mar 26, 2019

原因:因为开启了parseName 我就认为setValues 里面的 key 是结构化的,这种情况下 dialog里面的form其实还没有初始化出来,所以无法判断真实的key是啥,就赋值不了了。
临时解决方案:所以用 setValue 替代 setValues 可以解决问题。

//        this.field.setValues(nextProps.release);
  for(var i in nextProps.release) {
    this.field.setValue(i, nextProps.release[i]);
  }

@youluna
Copy link
Member

youluna commented May 15, 2019

https://riddle.alibaba-inc.com/riddles/f0979d0f when parseName is true, users can't set default value, too.

@jdkahn
Copy link
Contributor

jdkahn commented May 16, 2019

The design of the Field component is such that the values passed to the constructor will be ignored when parseName is true. This is because it has not initialized the form items yet. I see a few solutions to this issue:
(1) Use the init function on the input instead of setting form values prop. {...init('type.a', { initValue: defaultValue.type.a})}. This requires no change to the library.

(2) Add a function that parses values prop and added each to the field even if there are no inputs with that name. This will not affect when parseName is false. Developers will need to be careful to only pass values they wish to use.

@youluna @bindoon What do you think about solution (2)?

@bindoon
Copy link
Member

bindoon commented May 16, 2019

added each to the field even if there are no inputs with that name

there will be a lot of keys not used. and when people use getValues may get extra values. and arrays has two ways to write

values: {
  a: [{b:1}],
}

=>

a.0.b
or
a[0]['b']

if values have a object type

values: {
  c: {value:1, label: 'i am object'}
}

and people want init('c') not init('c.label')

in my think. when people pass values we just store it. when init we parse the real value from stored values

@jdkahn jdkahn closed this as completed May 24, 2019
@bindoon
Copy link
Member

bindoon commented May 24, 2019

fixed in PR: #683

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

4 participants