简体   繁体   English

每行一个表格(每列一个字段),每个表格都有按钮:如何管理脏状态?

[英]One form by row (fields for every column) with buttons for each: how to manage the dirty state?

I would like to handle the dirty state for every single row I have in my table. 我想处理表中每一行的脏状态。 Unfortunately, adding a form around a would break the table, and I can't create it inside since I have a field for every different column. 不幸的是,在a周围添加一个表单会破坏表格,并且由于在每个不同的列都有一个字段,所以无法在其中创建表格。 My last column for each row contains buttons: Delete and Update. 每行的最后一列包含按钮:删除和更新。 Update appears only if one of the field of this row has been made dirty. 仅当此行的一个字段被弄脏时,才会显示更新。

Somehow, it works already but I am checking each .pristine for every field on that row ( #name="ngModel" ). 某种程度上,它已经可以工作了,但是我正在检查该行( #name="ngModel" )上每个字段的每个.pristine。 My rows are created through something like *ngFor="let row of rows" . 我的行是通过*ngFor="let row of rows" I believe it would be better to check the .dirty or .pristine on a form rather than on every single element. 我相信最好在表单上而不是在每个元素上检查.dirty.pristine

Also, if I actually to the update, there is no way I can remove that .dirty status (I tried replacing the data for that row by removing from the array and re-adding it but it is still dirty). 另外,如果我确实要进行更新,则无法删除该.dirty状态(我尝试通过从阵列中删除并重新添加该行来替换该行的数据,但它仍然很脏)。

Is there a technique to go around that? 有解决这个问题的技术吗?

You could use ngModelGroup around each of your rows. 您可以在每行中使用ngModelGroup。 Then you can check the dirty flag for the group. 然后,您可以检查该组的脏标志。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据列数显示下拉字段并为 react js 中的每个 dropdwon 单独管理状态? - How to display dropdown fields based on column count and manage state individually for each dropdwon in react js? reactjs中如何管理每一行的state? - How do I manage the state of each row in react js? 如何验证每个字段的多步骤表单和消息显示 - How to validate a multiple step form and message display for each and every fields 如何分隔mysql db行中的每一列? 在拉拉韦尔 - how to separate each and every column in the mysql db row ? in laravel 如何管理带有父字段和子字段的表单的显示 - How to manage the display of a form with parent and child fields 反应初始 state:表格的每一行中有 2 个单选按钮 - React initial state: 2 Radio Buttons in each row of a Table 将视图的脏状态传播到包含窗体 - Propagating view's dirty state to the containing form 如何在反应中提交带有单选按钮的表单并根据提交的值将 state 递增 1? - How to submit a form with radio buttons in react and increment the state by one based on the value submitted? 提交表单并在一个字段中搜索其他 3 个按钮后,如何在浏览器中保存或保留信息/状态 - How do I save or keep information/state in the browser after submitting form and searching with one field for 3 other buttons jQuery / JavaScript如何获取单击它的按钮的值,每行按钮只能激活一个按钮 - jQuery/JavaScript how to get value of button that click on it, each row of buttons can only active only one button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM