Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
b4ccb36e
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
b4ccb36e
编写于
3月 09, 2023
作者:
O
openharmony_ci
提交者:
Gitee
3月 09, 2023
浏览文件
操作
浏览文件
下载
差异文件
!15175 修改promisify示例代码,uuid函数描述,增加convertToJSObject接口的错误码捕获【OpenHarmony-3.2-Beta5】
Merge pull request !15175 from jwx1068251/OpenHarmony-3.2-Beta5
上级
b4eb5ebc
21775e9b
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
54 addition
and
28 deletion
+54
-28
zh-cn/application-dev/reference/apis/js-apis-convertxml.md
zh-cn/application-dev/reference/apis/js-apis-convertxml.md
+21
-15
zh-cn/application-dev/reference/apis/js-apis-util.md
zh-cn/application-dev/reference/apis/js-apis-util.md
+33
-13
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-convertxml.md
浏览文件 @
b4ccb36e
...
...
@@ -47,21 +47,27 @@ convertToJSObject(xml: string, options?: ConvertOptions) : Object
**示例:**
```
js
let
xml
=
try
{
let
xml
=
'
<?xml version="1.0" encoding="utf-8"?>
'
+
'
<note importance="high" logged="true">
'
+
'
<title>Happy</title>
'
+
'
<todo>Work</todo>
'
+
'
<todo>Play</todo>
'
+
'
</note>
'
;
let
conv
=
new
convertxml
.
ConvertXML
()
let
options
=
{
trim
:
false
,
declarationKey
:
"
_declaration
"
,
instructionKey
:
"
_instruction
"
,
attributesKey
:
"
_attributes
"
,
textKey
:
"
_text
"
,
cdataKey
:
"
_cdata
"
,
doctypeKey
:
"
_doctype
"
,
commentKey
:
"
_comment
"
,
parentKey
:
"
_parent
"
,
typeKey
:
"
_type
"
,
nameKey
:
"
_name
"
,
elementsKey
:
"
_elements
"
}
let
result
=
JSON
.
stringify
(
conv
.
convertToJSObject
(
xml
,
options
));
console
.
log
(
result
);
let
conv
=
new
convertxml
.
ConvertXML
()
let
options
=
{
trim
:
false
,
declarationKey
:
"
_declaration
"
,
instructionKey
:
"
_instruction
"
,
attributesKey
:
"
_attributes
"
,
textKey
:
"
_text
"
,
cdataKey
:
"
_cdata
"
,
doctypeKey
:
"
_doctype
"
,
commentKey
:
"
_comment
"
,
parentKey
:
"
_parent
"
,
typeKey
:
"
_type
"
,
nameKey
:
"
_name
"
,
elementsKey
:
"
_elements
"
}
let
result
=
JSON
.
stringify
(
conv
.
convertToJSObject
(
xml
,
options
));
console
.
log
(
result
);
}
catch
(
e
)
{
console
.
log
(
e
.
toString
());
}
// 输出(宽泛型)
// {"_declaration":{"_attributes":{"version":"1.0","encoding":"utf-8"}},"_elements":[{"_type":"element","_name":"note","_attributes":{"importance":"high","logged":"true"},"_elements":[{"_type":"element","_name":"title","_elements":[{"_type":"text","_text":"Happy"}]},{"_type":"element","_name":"todo","_elements":[{"_type":"text","_text":"Work"}]},{"_type":"element","_name":"todo","_elements":[{"_type":"text","_text":"Play"}]}]}]}
```
...
...
zh-cn/application-dev/reference/apis/js-apis-util.md
浏览文件 @
b4ccb36e
...
...
@@ -26,7 +26,7 @@ format(format: string, ...args: Object[]): string
| 参数名 | 类型 | 必填 | 说明 |
| ------- | -------- | ---- | -------------- |
| format | string | 是 | 式样化字符串。 |
| ...args | Object[] | 否 | 替换式样化字符串通配符的数据
。
|
| ...args | Object[] | 否 | 替换式样化字符串通配符的数据
,此参数缺失时,默认返回第一个参数。
|
**返回值:**
...
...
@@ -69,6 +69,20 @@ let result = util.errnoToString(errnum);
console
.
log
(
"
result =
"
+
result
);
```
**部分错误码及信息示例:**
| 错误码 | 信息 |
| ------ | -------------------------------- |
| -1 | operation not permitted |
| -2 | no such file or directory |
| -3 | no such process |
| -4 | interrupted system call |
| -5 | i/o error |
| -11 | resource temporarily unavailable |
| -12 | not enough memory |
| -13 | permission denied |
| -100 | network is down |
## util.callbackWrapper
callbackWrapper(original: Function): (err: Object, value: Object )=
>
void
...
...
@@ -126,17 +140,23 @@ promisify(original: (err: Object, value: Object) => void): Function
**示例:**
```
js
function
aysnFun
(
str1
,
str2
)
{
if
(
typeof
str1
===
'
object
'
&&
typeof
str2
===
'
object
'
)
{
return
str2
function
fun
(
num
,
callback
)
{
if
(
typeof
num
===
'
number
'
)
{
callback
(
null
,
num
+
3
);
}
else
{
return
str1
callback
(
"
type err
"
);
}
}
let
newPromiseObj
=
util
.
promisify
(
aysnFun
);
newPromiseObj
({
err
:
"
type error
"
},
{
value
:
'
HelloWorld
'
}).
then
(
res
=>
{
}
const
addCall
=
util
.
promisify
(
fun
);
(
async
()
=>
{
try
{
let
res
=
await
addCall
(
2
);
console
.
log
(
res
);
})
}
catch
(
err
)
{
console
.
log
(
err
);
}
})();
```
## util.randomUUID<sup>9+</sup>
...
...
@@ -243,7 +263,7 @@ printf(format: string, ...args: Object[]): string
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| format | string | 是 | 式样化字符串。 |
| ...args | Object[] | 否 | 替换式样化字符串通配符的数据。 |
| ...args | Object[] | 否 | 替换式样化字符串通配符的数据
,此参数缺失时,默认返回第一个参数
。 |
**返回值:**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录