reactjs - Ant Design How to display "3 Selected" in Tree Select rather than display all value selected
问题描述
Basically in tree select when we select some options there will be shown the values chosen
Look at my code example
But when much data selected, the display will be larger and it's better for me to show the length of data selected than show all data selected
The expected result is 4 Selected
, 2 Selected
, 5 Selected
.
解决方案
用途maxTagCount
和maxTagPlaceholder
性质。
在这种情况下,SELECTED_THRESHOLD
它是常量,因此它将+ X Selected
在多个2
选定项目之后呈现。
您应该使您的条件更通用,例如取决于输入宽度等。
function Demo() {
const [selectedArray, setSelectedArray] = useState([]);
return (
<TreeSelect
value={selectedArray}
maxTagPlaceholder={`+ ${selectedArray.length - SELECTED_THRESHOLD} Selected`}
maxTagCount={SELECTED_THRESHOLD}
onChange={value => setSelectedArray(value)}
...
>
<TreeNode>
...
</TreeNode>
</TreeSelect>
);
}
检查演示。
推荐阅读
- json - 将 JSON 字符串转换为 Python 对象
- python - 保存 OptionMenu 输入 - tkinter
- mongodb - 如何在 Windows 7 中连接到 MongoDB
- ipad - MKMapView 不缩放到 iPad 视图
- android - mailto:在我的 webview 应用程序上不起作用
- hive - 如何在java中知道连接的Hive Server
- google-api-php-client - 为什么我在 Google G Suit 中插入时会收到 Invalid Parent Orgunit Id 的错误?
- python - 即使输入形状相同,由于输入形状不同,keras 合并连接失败
- javascript - 通过反应上下文 api 将子状态传递给父组件
- html - Access-Control-Request-Headers 是否需要在 bot OPTIONS 中并遵循请求?