首页 文章

Aurelia没有正确地转换Set和Spread运算符

提问于
浏览
0

我正在尝试使用aurelia从一些json数据中生成一个唯一的组名列表 . 代码在Chrome中使用普通的javascript工作,但在Aurelia中运行时会抛出错误 . 见小提琴 .

我得到的错误是'concat不是一个函数' . 它似乎是babel或webpack的问题 . 下面的代码是我在浏览器中看到的转换版本 .

var groupList = new Set(jsonData.map(function (x) {
  return x.group.name;
})).concat(); //concat is not a function

这是我的代码:

let jsonData = [
  { index: '0', name: 'INCH', factor: '12', desc: '', magnitude: '1', group: {name: 'length'} },
  { index: '1', name: 'FOOT', factor: '3', desc: '', magnitude: '2', group: {name: 'length'} },
  { index: '2', name: 'YARD', factor: '3', desc: '', magnitude: '3', group: {name: 'length'} },
  { index: '6', name: 'SQ FOOT', factor: '3', desc: '', magnitude: '2', group: {name: 'area'} },
  { index: '7', name: 'SQ YARD', factor: '3', desc: '', magnitude: '3', group: {name: 'area'} }
];

createGroups();

function createGroups() {
  const groupList = [...new Set(jsonData.map(x => x.group.name))];
  debugger;
}

如果我在Babel的网站上插入下面的代码,它产生的代码与我从Aurelia获得的代码完全不同 . 想到也许我有一个旧版本的Babel所以我更新到最新版本但仍然得到相同的错误 . 有任何解决方法或解决方案吗?

const groupList = [...new Set(jsonData.map(x => x.group.name))];

JSFiddle:http://jsfiddle.net/chrisevich/e1v9rpg2/96/

1 回答

  • 0

    在babelrc.js中将'loose'设置为false可以解决问题 .

相关问题