react-native - 如何在 react-native pell 富编辑器中设置字符限制?
问题描述
我想在 Richeditor 中设置最大字符长度 3000。我正在使用 react-native-pell-rich-editor。当用户插入超过 3000 个字符时,所有多余的字符都应自动删除。我正在接收 html 内容。
那么这个问题有什么解决方案吗?
这是我的代码:
<RichEditor
disabled={false}
initialContentHTML={summary}
style={{
height: "100%",
backgroundColor: "white",
flex: 1,
paddingTop: 1,
paddingBottom: 5,
justifyContent: "center",
minHeight: "100%",
minWidth: "100%",
width: "100%",
}}
showsVerticalScrollIndicator={false}
scrollEnabled={false}
ref={editor}
placeholder={"Write summary (Max 3000 char)"}
onChange={changeHTML}
/>
解决方案
我的解决方案:
changeHTML= (val) => {
if(val != this.prevDescVal){
let rawVal = val;
if(val.replace(/<[^>]*>/g, '').length > 1500 ){
this.richtext.current?.setContentHTML('');
this.richtext.current?.insertHTML(this.prevDescVal);
this.toast.show({
text: "Maximum limit 1500",
type: "failed",
});
}else{
this.prevDescVal = rawVal;
}
}
}
推荐阅读
- java - 您可以使用 ++ 运算符增加长文字并访问 java 中的整个长文字范围吗?
- javascript - 如何获取点击查询的值?
- r - 将拆分数据转换为r中的数据框
- authentication - 如何在 CakePHP 的身份验证插件中更改查找器模型
- reactjs - 使用 IdentityServer4 连接到 AzureAD 而不是直接连接到 AzureAD 有什么好处?
- arrays - 有没有一种有效的方法来比较这些数组?
- dom - Elm 如何制作自定义事件解码器以在鼠标滚轮移动时获取鼠标 x/y 位置
- python - 如何为 += 修复 TypeError 不支持的操作数类型:“DeferredAttribute”和“int”
- java - Eclipse 控制台在运行程序的过程中会自行清除的一些原因是什么?
- mysql - 如何在同一个查询中选择我在上面插入的值?