TypeError:无法读取未定义的属性“status”

时间:2017-02-26 16:46:22

标签: javascript reactjs redux react-redux redux-saga

我想将设备移动到创建的组(仅当选择任何一个设备时才会显示组设备)但是我收到错误

  

TypeError:无法读取未定义

的属性“status”

同样在createGroupSuccess中,应该传递updatedDevice对象但是当我在createGroupSuccess操作中控制时,我得到整个设备对象。这就是为什么我在尝试移动时无法在设备对象中添加组。

function* createGroup(action) {
  const device = yield select(selectDevice(), action);
  const updatedDevice = { id: device.get('id') };
  // const group = fromJS(action.group);
  // if (action.deviceId) {
  //   group = device.getIn(['device_group', action.deviceId]);
  //   group = group.mergeDeep(action.group);
  //   console.log('group inside if block', group);
  // }
  updatedDevice.device_group = action.group;
  if (action.group) {
    yield call(POST(`/device/${updatedDevice.id}`, createGroupSuccess, createGroupError, updatedDevice));
  }
}

function* rootSaga() {
  yield takeEvery(CREATE_GROUP, createGroup);
}


export function createGroup(group, deviceId) {
  return {
    type: CREATE_GROUP,
    group,
    deviceId,
  };
}

export function createGroupSuccess(device) {
  console.log('group in success', device);
  return {
    type: CREATE_GROUP_SUCCESS,
    device,
  };
}

export function createGroupError(error) {
  return {
    type: CREATE_GROUP_ERROR,
    error,
  };
}

case CREATE_GROUP:
  return state
    .set('loading', true)
    .set('error', null);

case CREATE_GROUP_SUCCESS:
  console.log('success', action);
  return state.set('loading', false).set('error', null)
    .setIn(['devices', action.device.data.id, 'device_group', action.device.data]);

我的设备对象

device:Object
  data:Object
    description: null,
    device_group: null,
    id: "7eb006d6db50479aa47f887da0d4f10e",
    name: "Fan Speed"

在创建群组时正在选择的设备对象中创建群组的错误在哪里?

更新

export function POST(apiUri, onSuccess, onError, data) {
 return dataLoader(apiUri, onSuccess, onError, data);
}

export function dataLoader(apiUri, onSuccess, onError, data) {
  return function* () {  // eslint-disable-line func-names
    const requestURL = `${API_BASE}${apiUri}`;
    try {
      let options;
      if (data !== undefined) {
        options = {
          method: 'POST',
          body: JSON.stringify(data),
          headers: {
            'Content-Type': 'application/json',
            'X-CSRFToken': Cookies.get('csrftoken'),
            'X-Requested-With': 'XMLHttpRequest',
          },
        };
      }
      const response = yield call(requestJSON, requestURL, options);
      yield put(onSuccess(response));
    } catch (e) {
      let error = null;
      try {
        error = yield call(() => e.response.json());
      } catch (_) {
        error = {
          errors: [{
            'code': e.response.status,
            'msg': e.response.statusText,
          }],
        };
      }
      yield put(onError(error));
    }
  };
}

1 个答案:

答案 0 :(得分:0)

尝试使用sendStatus替换状态