naive-ui icon indicating copy to clipboard operation
naive-ui copied to clipboard

Select 组件 render-label 和 value-field 同时使用

Open zuihou opened this issue 1 year ago • 5 comments

问题的清晰而简明的描述

const formState = reactive({
  orgList: [ {id: '1', name: '111', type: '1'1}, {id: '2' , name: '2' , type: '2'} ] 
  orgId: ''
});

function renderLabel(option: SelectOption): VNodeChild {
  return [
    h(
      NTag,
      { type: ORG_TYPE_TAG_MAP.get(option.type), class: 'mr-2' },
      { default: () => ORG_TYPE_MAP.get(option.type) }
    ),
    option.name as string
  ];
}

<NSelect v-model:value="formState.orgId" :options="formState.orgList"  value-field='id' :render-label="renderLabel"></NSelect>

上述代码,能正常渲染下拉框, 但在选中后,无法回显。

image

建议的解决方案

支持 render-label 和 value-field 同时使用

备选方案

No response

附加上下文

No response

验证

  • [X] 阅读 贡献指南
  • [X] 阅读 文档
  • [X] 检查是否已经存在请求相同功能的问题,以避免创建重复的问题。

zuihou avatar Mar 22 '24 13:03 zuihou

提供个复现链接

jahnli avatar Mar 22 '24 13:03 jahnli

提供个复现链接

https://github.com/zuihou/soybean-admin/blob/main/src/views/multi-menu/first_child/index.vue

zuihou avatar Mar 23 '24 12:03 zuihou

我也遇到了跟你一模一样的问题 这个解决了嘛

zouh7 avatar Sep 23 '24 03:09 zouh7