Ant Design Vue Select 显示现有项目
在 Vue 中使用 Ant Design。在多选组件中,用户能够选择和取消选择关联的对象。但是,预先存在的关联对象的现有标记应显示 item.name,而不是显示“未定义”。它也不会在选择框中的现有对象旁边显示复选标记。但是,在提交时,“未定义”对象被正确提交。新选项正确显示在选择框中。
这是视图中的元素:
<a-form-item :label="`${contact.name}'s Outlets`"
:wrapperCol="{lg: {span: 20}, sm: {span: 24} }">
<a-select
mode="multiple"
v-model="contact.outlets"
style="width: 100%"
placeholder="Please select"
>
<a-select-option v-for="outlet in outlets" :key="outlet.name" :value="outlet.id">
{{ outlet.name }}
</a-select-option>
</a-select>
</a-form-item>
Using Ant Design in Vue. In a Multi-select component, user is able to select and unselect associated objects. However, the existing tokens of preexisting associated objects should show the item.name, but instead show "undefined". It also does not show a checkmark next to existing objects in the select box. However, on submit, the "undefined" object is submitted correctly. New choices display within the select box correctly.
Here is the element in the view:
<a-form-item :label="`${contact.name}'s Outlets`"
:wrapperCol="{lg: {span: 20}, sm: {span: 24} }">
<a-select
mode="multiple"
v-model="contact.outlets"
style="width: 100%"
placeholder="Please select"
>
<a-select-option v-for="outlet in outlets" :key="outlet.name" :value="outlet.id">
{{ outlet.name }}
</a-select-option>
</a-select>
</a-form-item>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如注释中所示,您使用
contact.outlets[]
中的对象元素作为选择的初始值。但是,a-select
的value
属性绑定到每个元素的id
,因此找不到匹配项:As indicated in comments, you used an object element in
contact.outlets[]
for the initial value of the select. However, thea-select
'svalue
properties are bound to each element'sid
, so no match is found:Solution
Instead of the object as initial value, use the object's
id
.Composition API
demo 1
Options API
demo 2