如何在地图中屈服?

时间:2018-01-20 06:40:49

标签: react-native yield array.prototype.map

我正在使用react native来构建我的应用程序,我正在尝试使用下面的代码将我的变量转换为camelCase

export default function formatToCamelCase(inputObject: {[key: string]: any}) {
  let snakeKeys = Object.keys(inputObject);
  let newObject = {};

  for (let key of snakeKeys) {
    if (typeof inputObject[key] !== 'object') {
      newObject[parseToCamelCase(key)] = inputObject[key];
    } else if (inputObject[key] !== null && !Array.isArray(inputObject[key])) {
      newObject[parseToCamelCase(key)] = formatToCamelCase(inputObject[key]);
    } else {
      newObject[parseToCamelCase(key)] = inputObject[key];
    }
  }
  return newObject;
}

export function formatArrayToCamelCase(inputArray: Array<{[key: string]: any}>) {
  return inputArray.map((object) => {
    return formatToCamelCase(object);
  });
}

我试图在函数中调用formatArrayToCamelCase方法(在一个单独的文件中):

import formatToCamelCase, {formatArrayToCamelCase} from '../helpers/formatToCamelCase';

export function* fetchWeighInWeighOutEvent(action: FetchWeighInWeighOutEventAction): any {
  ...
  Object.values(locations).map((location) => {
    let timeslotsArray = location.timeslots;
    if (timeslotsArray.length > 0) {
      //Problem here - shows that yield is a reserved word
      let camelCaseTimeslots = yield call(formatArrayToCamelCase, timeslotsArray);
    }
  });

我无法将yield调用放在.map中,当尝试运行代码时,我收到以下错误: SyntaxError:yield是一个保留字

如何克服这个问题,以便我可以调用formatArrayToCamelCase函数并相应地转换我的数组?

0 个答案:

没有答案