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

创建同名字兄弟节点覆盖 #87

Open
chengandguo opened this issue Dec 24, 2023 · 0 comments
Open

创建同名字兄弟节点覆盖 #87

chengandguo opened this issue Dec 24, 2023 · 0 comments

Comments

@chengandguo
Copy link

chengandguo commented Dec 24, 2023

如果子节点包含field_2, 创建兄弟节点需要从3开始
`一种可能得修复方法
getRandomName(propertiesData) {
const currentField = "field_" + fieldNum++;
for (const key in propertiesData) {
if (key === currentField) {
return this.getRandomName(propertiesData);
}
}
return currentField;
},

addFieldAction: function (state, action, oldState) {
const keys = action.prefix;
let oldData = oldState.data;
let name = action.name;
let propertiesData = utils.getData(oldData, keys);
let newPropertiesData = {};

let parentKeys = utils.getParentKeys(keys);
let parentData = utils.getData(oldData, parentKeys);
let requiredData = [].concat(parentData.required || []);

if (!name) {
  newPropertiesData = Object.assign({}, propertiesData);
  let ranName = "field_" + fieldNum++;
  newPropertiesData[ranName] = utils.defaultSchema.string;
  requiredData.push(ranName);
} else {
  for (let i in propertiesData) {
    newPropertiesData[i] = propertiesData[i];
    if (i === name) {
      let ranName = this.getRandomName(propertiesData);   // 不能简单自增需要判断
      newPropertiesData[ranName] = utils.defaultSchema.string;
      requiredData.push(ranName);
    }
  }
}
utils.setData(state.data, keys, newPropertiesData);
// add required
parentKeys.push("required");
utils.setData(state.data, parentKeys, requiredData);

}
`

@chengandguo chengandguo changed the title 创建同名字,子节点覆盖 创建同名字兄弟节点覆盖 Dec 24, 2023
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