【发布时间】:2016-08-01 21:43:40
【问题描述】:
我正在尝试将以下内容转换为工作,但我认为这是一个 Es5/ES6 问题。帮助表示赞赏。
this.rows = Array.from(Array(Math.ceil(this.subCategoryModels.length / 3)).keys());
我目前遇到打字错误:
[ts]
Property 'from' does not exist on type 'ArrayConstructor'.
any
和
[ts]
Property 'keys' does not exist on type 'any[]'.
any
【问题讨论】:
-
“我认为这是一个 Es5/ES6 问题” - 你是想为 ES5 还是 ES6 编写?
Array.from()和.keys()都是 ES6 方法,所以显然它们在 ES5 中不起作用。 -
尝试插入“新”,例如:“Array.from(new Array(Math...”) 看看是否有帮助。
-
我尝试以下操作,但仍然遇到相同的错误。
this.rows = Array.from(new Array(Math.ceil(this.subCategoryModels.length / 3)).keys()); -
这行得通,但我不认为它很优雅。
for (var index = 0; index < Math.ceil(this.subCategoryModels.length / 3); index++) { this.rows.push(index); }
标签: javascript arrays typescript ecmascript-6 es5-shim