# Filter 自定义处理函数

> 面对不同的数据接口，需要提交不同类型的数据格式的时候，用户可以自己写个函数来进行处理。

## 初识

现在假如在引入RCRE的时候，已经给RCRE引擎引入了下面的自定义函数

```javascript
function toUpperCase(word) {
    return word.toUpperCase();
}
```

这个函数可以将所有的传入的函数都转成大写。

那么在RCRE的配置的任意一个ExpressionString执行环境内部，都可以采用如下的方式进行调用。

```text
#ES{toUpperCase("A")}
```

其余的事情，RCRE会帮助你搞定。

## 作为函数

直接使用#ES, 就能将filter函数转换成配置中的函数，可应用在组件的一些特殊功能上面。

函数具体接收的参数，由具体实际调用的情况所决定。

当然，也可以把函数当做成参数，作为变量来使用。

```javascript
function simpleFunc(a, b, c, d) {
    return a + b + c + d;
}

window.RCRE.filter.setFilter('simpleFunc', simpleFunc);
```

```json
{
    "body": [{
        "type": "container",
        "model": "name",
        "children": [
            {
                "type": "button",
                "text": "click",
                "trigger": [{
                    "event": "onClick",
                    "targetCustomer": "$this",
                    "params": {
                        "func": "#ES{simpleFunc}"
                    }
                }]
            },
            {
                "type": "text",
                "text": "#ES{$data.func(1,2,3,4)}"
            }
        ]
    }]
}
```

## DEMO

在使用单个文件安装的情况下，使用如下的方式导入filter函数

```__rcre_filter
function toUpperCase(word) {
    return word.toUpperCase();
}

window.RCRE.filter.setFilter('toUpperCase', toUpperCase);
```

```json
{
    "body": [
        {
            "type": "container",
            "model": "syncInput",
            "children": [
                {
                    "type": "input",
                    "name": "source",
                    "style": {
                        "width": 120
                    }
                },
                {
                    "type": "text",
                    "text": "#ES{toUpperCase($data.source)}"
                }
            ]
        }
    ]
}
```
