Commit 5dd3a784 by hfpp2012 yinsigan

删除最后一个元素

1 parent 328e72f1
...@@ -6,3 +6,7 @@ export const cloneElement = (element) => ({ ...@@ -6,3 +6,7 @@ export const cloneElement = (element) => ({
export const deleteLastElement = () => ({ export const deleteLastElement = () => ({
type: 'DELETE_LAST_ELEMENT' type: 'DELETE_LAST_ELEMENT'
}) })
export const deleteElement = () => ({
type: 'DELETE_ELEMENT'
})
...@@ -14,12 +14,6 @@ class ElementGroup extends React.Component { ...@@ -14,12 +14,6 @@ class ElementGroup extends React.Component {
this.setState({elements: elements}) this.setState({elements: elements})
} }
// 返回element的index为-1, 删除最后一个元素
deleteLastElement() {
const elements = ReactAddonsUpdate(this.state.elements, { $splice: [[-1, 1]] })
this.setState({elements: elements})
}
sidebar() { sidebar() {
return document.getElementById('sidebar') return document.getElementById('sidebar')
} }
......
...@@ -11,6 +11,10 @@ const headergroup = (state = init_state, action) => { ...@@ -11,6 +11,10 @@ const headergroup = (state = init_state, action) => {
...state, ...state,
action.element action.element
] ]
case 'DELETE_LAST_ELEMENT':
return [
...state.slice(0, -1),
]
default: default:
return state return state
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!