reactjs - 使用其内部 tabComponent 时,syncfusion 输入字段未连接到状态
问题描述
我已经尝试了很多方法来找到我的问题的解决方案,也搜索了很多但找不到我的解决方案。
我使用syncfusion TabComponent在tabcontent中显示一个输入html,我希望在单击按钮更新状态并更改输入值时,但第一个tabContent中的输入其值不会改变。但是标签内容之外的输入效果很好
import React, { Component } from "react"; import { TabComponent,
TabItemDirective, TabItemsDirective } from "@syncfusion/ej2-react-
navigations";
export default class FormDataBinding extends Component {
constructor(props) { super(props);
this.state = {
name: "name"
};
}
btnClick = () => {
let newName = new Date();
this.setState({ name: newName });
};
tabContent1 = () => {
return (
<div>
{/* it's not working because it's inside tabComponent */}
<input type="text" value={this.state.name} key="name" id="name">
</input>
<button onClick={this.btnClick.bind(this)}>click hear</button>
</div>
);
};
render() {
let headertext;
// Mapping Tab items Header property
headertext = [{ text: "Twitter", iconCss: "e-twitter" }];
return (
<div className="control-pane">
<div className="control-section tab-control-section">
{/* it works */}
<input
type="text"
value={this.state.name}
key="name"
id="name"
></input>
{/*--------------*/}
<TabComponent heightAdjustMode="Auto" id="defaultTab">
<TabItemsDirective>
<TabItemDirective
header={headertext[0]}
content={this.tabContent1.bind(this)}
/>
</TabItemsDirective>
</TabComponent>
</div>
</div>
);
}
}`
解决方案
我们已经使用 content 属性中模板中的自定义数据实现了您的要求。我们已将模板和数据传递给 Tab 内容以检索 setState 更改。这个问题的原因是因为 setstate 在 Tab 内容模板中没有立即发生变化。我们附上了以下示例供您参考。
示例:https ://codesandbox.io/s/flamboyant-cartwright-o8isb
问候,
卡尔蒂
推荐阅读
- javascript - 上传图片到本地文件夹 React JS
- php - 无法完全覆盖 Laravel mail.php 中的回复
- java - Quarkus 开发模式/实时编码是否不适用于 JPMS/Java 模块?
- delphi - 在 Delphi FMX 中设置 TlistView 水平显示
- python - tkinter 中的 RTL 网格
- macos - CodeRunner 4.0.3 (Mac 软件) - 如何在终端窗口中执行程序?
- mysql - MYSQL 将左连接中的重复行与所有数据合并为一行
- ios - 从两个静态库(libssl.a、libcrypto.a)中创建 XCFramework
- typescript - 打字稿:如何在“let”声明的变量中捕获虚假值?
- reactjs - 如何使用带有 Gatsby.js 的地图功能正确渲染图像