Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
f9c0fff9
Commit
f9c0fff9
authored
Jan 08, 2018
by
afc163
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Should not mutate state, close #602
parent
9c690972
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
9 deletions
+11
-9
src/routes/Forms/TableForm.js
src/routes/Forms/TableForm.js
+11
-9
No files found.
src/routes/Forms/TableForm.js
View file @
f9c0fff9
...
...
@@ -17,8 +17,8 @@ export default class TableForm extends PureComponent {
});
}
}
getRowByKey
(
key
)
{
return
this
.
state
.
data
.
filter
(
item
=>
item
.
key
===
key
)[
0
];
getRowByKey
(
key
,
newData
)
{
return
(
newData
||
this
.
state
.
data
)
.
filter
(
item
=>
item
.
key
===
key
)[
0
];
}
index
=
0
;
cacheOriginData
=
{};
...
...
@@ -35,14 +35,15 @@ export default class TableForm extends PureComponent {
}
toggleEditable
(
e
,
key
)
{
e
.
preventDefault
();
const
target
=
this
.
getRowByKey
(
key
);
const
newData
=
this
.
state
.
data
.
map
(
item
=>
({
...
item
}));
const
target
=
this
.
getRowByKey
(
key
,
newData
);
if
(
target
)
{
// 进入编辑状态时保存原始数据
if
(
!
target
.
editable
)
{
this
.
cacheOriginData
[
key
]
=
{
...
target
};
}
target
.
editable
=
!
target
.
editable
;
this
.
setState
({
data
:
[...
this
.
state
.
data
]
});
this
.
setState
({
data
:
newData
});
}
}
remove
(
key
)
{
...
...
@@ -51,7 +52,7 @@ export default class TableForm extends PureComponent {
this
.
props
.
onChange
(
newData
);
}
newMember
=
()
=>
{
const
newData
=
[...
this
.
state
.
data
]
;
const
newData
=
this
.
state
.
data
.
map
(
item
=>
({
...
item
}))
;
newData
.
push
({
key
:
`NEW_TEMP_ID_
${
this
.
index
}
`
,
workId
:
''
,
...
...
@@ -69,8 +70,8 @@ export default class TableForm extends PureComponent {
}
}
handleFieldChange
(
e
,
fieldName
,
key
)
{
const
newData
=
[...
this
.
state
.
data
]
;
const
target
=
this
.
getRowByKey
(
key
);
const
newData
=
this
.
state
.
data
.
map
(
item
=>
({
...
item
}))
;
const
target
=
this
.
getRowByKey
(
key
,
newData
);
if
(
target
)
{
target
[
fieldName
]
=
e
.
target
.
value
;
this
.
setState
({
data
:
newData
});
...
...
@@ -102,13 +103,14 @@ export default class TableForm extends PureComponent {
cancel
(
e
,
key
)
{
this
.
clickedCancel
=
true
;
e
.
preventDefault
();
const
target
=
this
.
getRowByKey
(
key
);
const
newData
=
this
.
state
.
data
.
map
(
item
=>
({
...
item
}));
const
target
=
this
.
getRowByKey
(
key
,
newData
);
if
(
this
.
cacheOriginData
[
key
])
{
Object
.
assign
(
target
,
this
.
cacheOriginData
[
key
]);
target
.
editable
=
false
;
delete
this
.
cacheOriginData
[
key
];
}
this
.
setState
({
data
:
[...
this
.
state
.
data
]
});
this
.
setState
({
data
:
newData
});
}
render
()
{
const
columns
=
[{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment