HarmonyOS kotlin val personList = (1..100).map { Person("name$it", "id$it") } 这行代码ArkTS里怎么写?

HarmonyOS
4天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

ts:

class Person {
  name: string;
  id: string;
  constructor( name: string,  id: string) {
    this.name = name;
    this.id = id;
  }
}
const people: Person[] = Array.from({ length: 100 }, (_, index) => new Person(`name${index + 1}`, `id${index + 1}`));
interface Person1 {  
    name: string;  
    id: string;  
}
const people: Person1[] = Array.from({ length: 100 }, (_, index) => ({ name: `name${index + 1}`, id: `id${index + 1}` }));

ArkTS:

class Person {
  name: string;
  id: string;
  constructor( name: string,  id: string) {
    this.name = name;
    this.id = id;
  }
}
let people= Array.from<number, Person>({ length: 100 }, (_, index:number):Person => new Person(`name${index + 1}`, `id${index + 1}`));
interface Person1 {  
    name: string;  
    id: string;  
}
let people1= Array.from<number, Person1>({ length: 100 }, (_, index:number):Person1 => ({name:`name${index + 1}`, id:`id${index + 1}`}));
分享
微博
QQ
微信
回复
4天前
相关问题
HarmonyOS ArkTS中运算符重载怎么
46浏览 • 1回复 待解决
求教一个sql语句传参怎么
3402浏览 • 1回复 待解决
HarmonyOS 获取相册的图片和视频ID
89浏览 • 1回复 待解决
HarmonyOS map转json怎么实现?
55浏览 • 1回复 待解决
HarmonyOS Kotlin编程语言IntArray咨询
124浏览 • 1回复 待解决
关于HarmonyOS如何支持 kotlin、js
377浏览 • 1回复 待解决
HarmonyOS JSON怎么Map
350浏览 • 1回复 待解决
HarmonyOS文件上传怎么
642浏览 • 1回复 待解决
这行的作用时什么?
2697浏览 • 1回复 待解决