智能客服
你问我答,随时在线为你解决问题
ArkTS中不支持通过索引访问字段,要使用索引的话可以考虑Record<key, value>,参考代码如下:
- class Student {
- data: Record<string, string> = { 'name': 'aaa', 'age': 'bbb' };
- }
-
- @Entry
- @Component
- struct KeyObject {
- build() {
- Column() {
- Button('click')
- .onClick(() => {
- let student = new Student();
- console.info(`${student.data['name']}`);
- })
- }
- .justifyContent(FlexAlign.Center)
- .alignItems(HorizontalAlign.Center)
- .width('100%')
- .height('100%')
- }
- }
智能客服
你问我答,随时在线为你解决问题
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功