[comment]: # translation:outdated

[comment]: # ({a7557797-a7557797})
# 更新

[comment]: # ({/a7557797-a7557797})

[comment]: # ({77f7fb70-476a7855})
### 描述

`object trigger.update(object/array triggers)`

方法用于更新目前的触发器.

::: noteclassic
此方法只适用于_Admin_和_Super admin_用户类型，调用该方法的权限可以在用户角色设置中被撤销. 前往 [用户角色](/manual/web_interface/frontend_sections/administration/user_roles) 以查看并了解更多信息.
:::

[comment]: # ({/77f7fb70-476a7855})

[comment]: # ({b7810df3-b918ffdf})
### 参数

`(object/array)` 需要更新的触发器属性.

`triggerid`属性必须在每个应用集中已定义，其他所有属性为可选项。只有传递过去的属性会被更新，其他所有属性仍然保持不变.

除了 [标准触发器属性](object#trigger) 之外， 该方法还接受以下参数.

| 参数         | [类型](/manual/api/reference_commentary#data_types) | 描述                                                         |
| ------------ | --------------------------------------------------- | ------------------------------------------------------------ |
| dependencies | array                                               | 依赖触发的触发器.<br><br>触发器必须已定义`triggerid`属性.    |
| tags         | array                                               | 触发器 [标签.](/manual/api/reference/trigger/object#trigger_tag) |

::: noteimportant
指定的触发器表达式必须为展开式.
:::

[comment]: # ({/b7810df3-b918ffdf})

[comment]: # ({18d0cc04-18d0cc04})
### 返回值

`(object)`返回一个对象，其中包含 triggerids 属性下已更新的触发器的 ID.

[comment]: # ({/18d0cc04-18d0cc04})

[comment]: # ({b41637d2-b41637d2})
### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({9a78a200-07c64481})
#### 启用一个触发器

启用触发器，即将其状态设置为0.

请求:

```json
{
    "jsonrpc": "2.0",
    "method": "trigger.update",
    "params": {
        "triggerid": "13938",
        "status": 0
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "triggerids": [
            "13938"
        ]
    },
    "id": 1
}
```

[comment]: # ({/9a78a200-07c64481})

[comment]: # ({cc24d689-b2bab7ce})
#### 替换触发器标签

为触发器替换标签.

请求:

```json
{
    "jsonrpc": "2.0",
    "method": "trigger.update",
    "params": {
        "triggerid": "13938",
        "tags": [
            {
                "tag": "service",
                "value": "{{ITEM.VALUE}.regsub(\"Service (.*) has stopped\", \"\\1\")}"
            },
            {
                "tag": "error",
                "value": ""
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "triggerids": [
            "13938"
        ]
    },
    "id": 1
}
```

[comment]: # ({/cc24d689-b2bab7ce})

[comment]: # ({38de55de-db463204})
#### 替换依赖项

替换触发器的依赖项.

[请求](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "trigger.update",
    "params": {
        "triggerid": "22713",
        "dependencies": [
            {
                "triggerid": "22712"
            },
            {
                "triggerid": "22772"
            }
        ]
    },
    "id": 1
}
```

响应:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "triggerids": [
            "22713"
        ]
    },
    "id": 1
}
```

[comment]: # ({/38de55de-db463204})

[comment]: # ({180a8172-180a8172})
### 源码

CTrigger::update() in *ui/include/classes/api/services/CTrigger.php*.

[comment]: # ({/180a8172-180a8172})
