企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
**callServerMethod** 调用服务端二开组件的方法,二开方法返回值可以是void或string **返回值** 无返回值,成功后回调函数(result.d即服务端接口返回值)和失败后回调函数 **参数** | 名称 | 类型 | 描述 |必填 | --- | --- | --- |--- | | method | string | 二开组件的方法名|是 | arg | string | 传递给二开组件方法的参数,可以为空 | | onsuccess | function | 访问成功后调用的回调函数 | | onerror | function | 访问出错后调用的回调函数 | | sync| bool| 是否同步调用 | **示例** ``` callServerMethod('GetTemplate', 2, function (result) { if (result.d) { } }, function (error) { showTip('操作失败!'); }); ``` 对应的二开方法声明如下 ``` public static string GetTemplate(Entities objContext, int uid, string type) { return ... } ``` objContext, uid这两个参数是固定的,分别表示数据库上下文和当前登录用户ID 参数type即前端传递过来的arg参数 如果arg参数为空,则二开方法就无此参数,如下 ``` callServerMethod('GetTemplate', '', function (result) { if (result.d) { } }, function (error) { showTip('操作失败!'); }); ``` 此时二开方法声明如下 ``` public static string GetTemplate(Entities objContext, int uid) { return ... } ``` 或者调用平台内置的一些方法,例如:获取当前用户的直接上级用户ID ``` callServerMethod('GetEmpDirector', '', function (r) { alert('直接上级用户ID为:' + r.d); }); ```