表格数据选中删除

183 阅读1分钟

删除函数:

  handleBtndel = (event) => {
    const { dispatch } = this.props;
    const { selectedRows } = this.state;  //state中selectedRows=[]
    if(!selectedRows) return;
    dispatch({
      type: 'listTableList/remove',
      payload: {
        key: selectedRows.map(row => row.key),
      },
      callback: () => {
        this.setState({
          selectedRows: [],
        });
      },
    });
  }

model:

const Model = {
    namespace: 'listTableList',
    effects: {
        * remove({ payload, callback }, { call, put }) {
            const response = yield call(removeRule, payload);
            yield put({
                type: 'save',
                payload: response,
            });
            if (callback) callback();
        },
    }
    reducers: {
        save(state, action) {
            return {...state, data: action.payload };
        },
    },
}

service:

export async function removeRule(params) {
    return request('/api/usersTable', {
        method: 'POST',
        data: {...params, method: 'delete' },
    });
}