提交 8e6ef5ef 编写于 作者: lizhongyi_'s avatar lizhongyi_

Merge branch 'master' of https://gitcode.net/dcloud/unidocs-zh

...@@ -90,3 +90,33 @@ console.log(map1.get('bar')); ...@@ -90,3 +90,33 @@ console.log(map1.get('bar'));
console.log(map1.get('baz')); console.log(map1.get('baz'));
// expected output: null // expected output: null
``` ```
### 常见操作
- 创建map
```ts
let map = new Map<string,any>()
map.put("name","zhangsan")
map.put("age",12)
//Map(2) {"name":"zhangsan","age":12}
console.log(map)
```
- 通过key访问map元素
```ts
let map = new Map<string,any>()
map.put("name","zhangsan")
map.put("age",12)
let nameVal = map['name']
//zhangsan
console.log(nameVal)
```
- 遍历map
```ts
let map = new Map<string,any>()
map.put("name","zhangsan")
map.put("age",12)
map.forEach(function(key:string,value:any){
console.log(key)
console.log(value)
})
```
...@@ -255,21 +255,21 @@ let resolveInfo = packageManager.queryIntentActivities(intent,0); ...@@ -255,21 +255,21 @@ let resolveInfo = packageManager.queryIntentActivities(intent,0);
这种情况下,我们建议的做法是将其先转换为UTS的Array对象再进行其他处理和操作 这种情况下,我们建议的做法是将其先转换为UTS的Array对象再进行其他处理和操作
```ts ```ts
let launcherList = UTSArray.fromNative(resolveInfo) let launcherList = Array.fromNative(resolveInfo)
console.log(clothing.length); console.log(clothing.length);
``` ```
下面汇总了常用的转换场景和代码: 下面汇总了常用的转换场景和代码:
##### 1 我有一个UTSArray 需要转换为其他类型 ##### 1 我有一个Array 需要转换为其他类型
```ts ```ts
let utsArr= ["hello","world"] let utsArr= ["hello","world"]
// UTSArray 转换 kotlin.collections.List // Array 转换 kotlin.collections.List
let kotlinList = utsArr.toKotlinList() let kotlinList = utsArr.toKotlinList()
// UTSArray 转换 kotlin.Array // Array 转换 kotlin.Array
let kotlinArray = utsArr.toTypedArray() let kotlinArray = utsArr.toTypedArray()
``` ```
...@@ -277,15 +277,15 @@ let kotlinArray = utsArr.toTypedArray() ...@@ -277,15 +277,15 @@ let kotlinArray = utsArr.toTypedArray()
##### 2 我有一个原生类数组类型 需要转成成UTS的Array ##### 2 我有一个原生类数组类型 需要转成成UTS的Array
```ts ```ts
// kotlin.collections.List 转换 UTSArray // kotlin.collections.List 转换 Array
let utsArr= mutableListOf("hello","world") let utsArr= mutableListOf("hello","world")
let kotlinList = UTSArray.fromNative(utsArr) let kotlinList = Array.fromNative(utsArr)
``` ```
```ts ```ts
// kotlin.Array 转换 UTSArray // kotlin.Array 转换 Array
let utsArr= arrayOf("hello","world") let utsArr= arrayOf("hello","world")
let kotlinList = UTSArray.fromNative(utsArr) let kotlinList = Array.fromNative(utsArr)
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册