angular - Primeng Inputtext:取消按钮功能
问题描述
我在 Angular 4 上工作,我正在使用 primnginputtext
和dataTable
. 我的页面显示了一个带有键及其值的表格,我的要求是当我单击edit
按钮时,其中的value
字段dataTable
将开始出现在文本字段中。当我cancel
应该撤消所有操作并显示文本字段的原始值时,当我单击保存时,我将进行服务调用以保存它。
我已经完成了,Save
但cancel
我无法弄清楚如何继续前进。谁能指导我如何实现取消按钮功能?
<button>Edit</button>
<button>Cancel</button>
<button>Save</button>
<p-dataTable [value]="fileInfo" [sortField]="sortF" [sortOrder]="sortO" (onSort)="changeSort($event)">
<p-column field="key" header="Vin" [sortable]="true"></p-column>
<p-column field="value" header="Year" [sortable]="true">
<ng-template let-col let-item="rowData">
<input id="float-input" type="text" size="30" pInputText value-"{{item.value}}">
</ng-template>
</p-column>
<p-footer>
<button type="button" label="Sort by Year" (click)="changeSort($event)" pButton></button>
</p-footer>
</p-dataTable>
this.fileInfo = [{
key: "Name",
value: "ABC"
},
{
key: "Age",
value: "45"
},
{
key: "Place",
value: "NY"
},
{
key: "Book",
value: "A1"
},
{
key: "Contact",
value: "123456"
}
]
解决方案
当您subscribing
打开时success store it in a variable
(或者您可以根据需要将其存储在两个或多个变量中)并且此变量将存储数据,除非您自愿更改它或重新刷新页面。所以,当你click on cancel assign the data stored in the variable to datatable.
推荐阅读
- node.js - 猫鼬 4 到 5:connection.db.collection() 未定义
- android - Swipe delete on Recycleview is very sensitive
- javascript - 编写将项目添加到不同状态数组的函数时遇到问题
- vba - if 和 for 循环包含在 while 循环 VBA 中
- azure - 如何测量 Azure Function 冷启动时间
- r - R Highcharter:格式化工具提示
- php - 为什么不打印用户表单提交消息(在浏览器停止确认表单提交警报后)
- hibernate - JPQL org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌:第 1 行附近的联合
- ios - Google Cast SDK 无法在带有 wifi 的 Xcode 9.4 模拟器上运行,但可在以太网上运行
- cassandra - 删除一行需要多长时间?