reactjs - 如何用打字稿解决reactjs中的这个多重选择不起作用
问题描述
我无法多次选择有一个连接错误代码“属性'连接'不存在类型'未知'。” 这是 .tsx 文件
const DropdownMultiselect =()=>{
return(
<>
<FormControl>
<Select
labelId="demo-mutiple-checkbox-label"
id="demo-mutiple-checkbox"
multiple
value={personName}
onChange={handleChangeMulti}
input={<Input />}
placeholder="Enter the Scene"
renderValue={(selected) => selected.join(',')}
>
{load? <Loader/> :<div className="custom-schedule-dropdown">
{sceneResponce.map((scene, index) =>
(
<MenuItem key={index} value={scene.scene_title}>
<Checkbox checked={personName.indexOf(scene.set) > -1} />
<div className='image-background'>
<img src={schendileIcon.default} className="schedule-icon" />
</div>
<div>
<div className='schedule-scene'>{scene.scene_title+' '+ '|'}{'
'+scene.environment+' '+ '-'}{' '+scene.set}</div>
<div className='schedule-location'>{scene.description}</div>
</div>
</MenuItem>
)
)}
</div>}
</Select>
</FormControl>
</>
)
}
屏幕输出:
解决方案
这unknown
实际上似乎是 Material UI 类型中的一个错误。该Select
组件应该能够value
根据您提供的道具推断类型。此问题已得到修复,但在 v5 发布之前不会包含此修复程序。
您需要将类型设置selected
为any
。将其设置为更准确的类型,例如string[]
由于unknown
组件类型中的
renderValue={(selected: any) => selected.join(',')}
看起来你的组件中有很多未定义的变量应该作为道具传递。
推荐阅读
- google-apps-script - 通过 https://groups.google.com/ cf AdminDirectory.Members.insert 添加时向群组成员发送邀请邮件
- python - 在我的距离计算器中不明白 TypeError 的原因
- facebook-graph-api - Facebook 登录无法请求 instagram_basic 权限
- xcode - 您知道我没有收到 Console.log 或 Appstoreconnect 崩溃报告的原因吗?
- java - Spring Boot - @MockBean 在测试用例中创建重复项
- vba - VBA 代码在逐步模式下工作,但在尝试运行宏时崩溃
- python - TypeError:不允许捕获不继承自 BaseException 的类
- javascript - 根据当前页面 url 更改按钮 href
- prometheus - 在开发过程中如何查询prometheus并控制结果?
- python-3.x - 如何附加包含在嵌套列表中的多个字典值