-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix: 修复单选框多选框 选择器未使用label作为选项 #1719
Conversation
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
} | ||
) | ||
form_data.value.form_field_list = _value | ||
sync_form_field_list() | ||
} | ||
const addFormField = (form_field_data: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
该部分有轻微逻辑问题:
useSync
方法名称应更改为sync_form_field_list
。- 处理新增字段的操作可以合并为以下代码:
// 在这里添加 new field data 到数组里,并通过 sync 函数同步到表单结构中
export function syncFieldLists(fieldTypeList: Array<any>, formData: any) {
// 先将新的字段列表复制一份以防止原数据被修改影响到新数据
const newFieldTypeList = cloneSpreadDeep(formData.form_field_list);
for (let i = 0; i < fieldTypeList.length; i++) {
const itemToAdd = fieldTypeList[i];
// 同步已存在的字段到新创建的字段对象上,但需要确保不会替换掉原来的值
try {
newFieldTypeList.find((f: any) => f.fieldValue === itemToAdd.addValue)
.setFieldValue(itemToAdd.getValue())
} catch(e: any) {
注意:这段代码中的处理方法没有考虑到类型匹配的情况。如果在传递给 addFormField 的参数和之前已经有的属性冲突,则可能不会正确处理。
其他地方整体来看语法无误。
textField: 'label', | ||
valueField: 'value', | ||
text_field: 'label', | ||
value_field: 'value', | ||
option_list: formValue.value.option_list | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
该段代码没有明显问题,逻辑清晰且语法正确。
textField: 'label', | ||
valueField: 'value', | ||
text_field: 'label', | ||
value_field: 'value', | ||
option_list: formValue.value.option_list | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
该段代码没有明显的差错或优化机会,只是简单的 HTML + Vue 实现了一个单选框表单组件,它包含一个 select 和两个输入字段 textField
和 valueField
。Vue 的 data 属性和方法也已正确设置。
在这个版本中:
- 标签选择 (input-type为singleselect),默认绑定到 "label" 字段,并可将值指定为"value".
- 使用 options 列出不同的选项。
尽管如此,如果你希望使用更现代的元素,请尝试移除 <el-form>
元素以及替换相应的数据属性。这可能包括将其更改为更具表现力的方式(例如通过 React 进行封装):
// 导入必要的库
import { ElForm } from 'element-plus';
const FormElementProps = {
inputType: 'SingleSelect',
defaultValues: null,
};
class SingleSelect extends HTMLElement {
constructor() {
super();
// 在这里添加额外的信息和逻辑处理
}
connectedCallback(event) {
this.$parent.addEventListeners(this);
}
handleInputChange = event => {
console.log("Input changed:", event.detail.value); // 示例:在控制台打印获取的用户输入值
};
}
请注意,在实际项目中可能需要对上述部分进行适当的修改以适应具体的业务需求。
fix: 修复单选框多选框 选择器未使用label作为选项