o2oa api: dict | o2oa开发平台-游戏厅捕鱼达人

module

this.dict是一个工具类,如果您在流程、内容管理、门户和服务管理中创建了数据字典,可以使用this.dict类对数据字典进行增删改查操作。
从v8.0版本开始,支持在门户和服务管理中创建数据字典。

syntax

//您可以通过this.dict()对本应用或其他应用的数据字典中的数据进行增删改查,如下:
var dict = new this.dict( options )

example

var dict = new this.dict({
    //type: 应用类型。可以为process  cms portal service。流程脚本默认为process,服务管理中默认为service。
   type : "cms",
   application : "bulletin", //流程、cms、门户管理的名称、别名、id。引用服务管理的数组字典则忽略该参数。
   name : "bulletindictionary", // 数据字典的名称、别名、id
});
//引用服务管理中的数据字典
var dict = new this.dict({
  "type": "service",
  "name": "dictname"
});
//引用流程管理中的数据字典
var dict = new this.dict({
  "type": "process",
  "application": "appname",
  "name": "dictname"
});
//引用内容管理中的数据字典
var dict = new this.dict({
  "type": "cms",
  "application": "appname",
  "name": "dictname"
});
//引用门户管理中的数据字典
var dict = new this.dict({
  "type": "portal",
  "application": "appname",
  "name": "dictname"
});

methods

static

get(pathopt, successopt, failureopt) → {object|array|string|number|boolean}

根据路径获取数据字典中的数据。

syntax

var data = dict.get( path, success, failure )

parameters

  • path string

    数据字典中的数据路径,允许使用中文。当路径为多级时,用点号(.)分隔。当值为空的时候,表示获取数据字典中的所有数据。

  • success function

    获取数据成功时的回调函数。流程设计后台脚本中无此参数。

  • failure function

    获取数据失败时的回调。流程设计后台脚本中无此参数。

returns

  • object array string number boolean

    返回数据字典的数据,类型和配置数据字典时候指定的一致。

example

已经配置好了如下图所示的数据字典

var dict = new this.dict({
    //type: 应用类型。可以为process  cms portal service。默认为process。
   type : "cms",
   application : "bulletin", //流程、cms、门户管理的名称、别名、id。引用服务管理的数组字典则忽略该参数。
   name : "bulletindictionary", // 数据字典的名称、别名、id
});
var data = dict.get();
//data的值为
{
   "category": [
       {
           "enable": true,
           "sequence": 1.0,
           "text": "公司公告",
           "value": "company"
       },
       {
           "enable": "false",
           "sequence": 2.0,
           "text": "部门公告",
           "value": "department"
       }
   ]
}
 var category = dict.get("category");
 //category的值为
 [
    {
       "enable": true,
       "sequence": 1.0,
       "text": "公司公告",
       "value": "company"
   },
    {
      "enable": "false",
      "sequence": 2.0,
       "text": "部门公告",
       "value": "department"
   }
 ]
 var array0 = dict.get("category.0");
 //array0 的值为
 {
   "enable": true,
   "sequence": 1.0,
   "text": "公司公告",
   "value": "company"
}
var enable = dict.get("category.0.eanble");
//enable 的值为 true

source

set(path, data, successopt, failureopt)

根据路径修改数据字典的数据。

syntax

dict.set( path, data, success, failure )

parameters

  • path string

    数据字典中的数据路径,允许使用中文。当路径为多级时,用点号(.)分隔。如果数据路径不存在,则报错。

  • data object | array | string | number | boolean

    修改后的数据

  • success function

    设置数据成功时的回调函数。流程设计后台脚本中无此参数。

  • failure function

    设置数据错误时的回调函数。流程设计后台脚本中无此参数。

examples

var dict = new this.dict({
    //type: 应用类型。可以为process  cms portal service。默认为process。
   type : "cms",
   application : "bulletin", //流程、cms、门户管理的名称、别名、id。引用服务管理的数组字典则忽略该参数。
   name : "bulletindictionary", // 数据字典的名称、别名、id
});
dict.set( "category", { text : "系统公告", value : "system" }, function(data){
   //data 形如
   //{
   //    "id": "80ed5f60-500f-4358-8bbc-b7e81f77aa39" //id为数据字典id
   //}
}, function(xhr){
   //xhr 为 xmlhttprequest
});

对example add的数据字典进行赋值,如下:

var dict = new this.dict({
    //type: 应用类型。可以为process  cms portal service。默认为process。
   type : "cms",
   application : "bulletin", //流程、cms、门户管理的名称、别名、id。引用服务管理的数组字典则忽略该参数。
   name : "bulletindictionary", // 数据字典的名称、别名、id
});
dict.set( "archiveoptions", [ { text : "是" }, { text : "否" } ]);
     //数据字典的值变为
 {
    "category": [
        {
            "enable": true,
            "sequence": 1.0,
            "text": "公司公告",
            "value": "company"
        },
        {
            "enable": "false",
            "sequence": 2.0,
            "text": "部门公告",
            "value": "department"
        },
        {
            "sequence" : 3.0,
            "text": "系统公告",
            "value": "system"
        }
    ],
    "archiveoptions" : [ { text : "是" }, { text : "否" } ]
}
dict.set( "category.2", { text : "县级公告", value : "county" }, function(data){
    //data 形如
    //{
    //    "id": "80ed5f60-500f-4358-8bbc-b7e81f77aa39" //id为数据字典id
    //}
 }, function(xhr){
    //xhr 为 xmlhttprequest
 });
  /数据字典的值变为
 {
    "category": [
        {
            "enable": true,
            "sequence": 1.0,
            "text": "公司公告",
            "value": "company"
        },
        {
            "enable": "false",
            "sequence": 2.0,
            "text": "部门公告",
            "value": "department"
        },
        {
            "text": "县级公告",
            "value": "county"
        }
    ],
    "archiveoptions" : [ { text : "是" }, { text : "否" } ]
}
dict.set( "category.1.sequence", 3 );
dict.set( "category.2.sequence", 2 );
     //数据字典的值变为
     {
    "category": [
        {
            "enable": true,
            "sequence": 1.0,
            "text": "公司公告",
            "value": "company"
        },
        {
            "enable": "false",
            "sequence": 3.0,
            "text": "部门公告",
            "value": "department"
        },
        {
            "sequence": 2.0,
            "text": "县级公告",
            "value": "county"
        }
    ],
    "archiveoptions" : [ { text : "是" }, { text : "否" } ]
}

下面是错误的赋值:

dict.set( "category_1", { text : "公司公告" } ); //出错,因为category_1在数据字典中不存在

source

add(path, data, successopt, failureopt)

根据路径新增数据字典的数据。

syntax

dict.add( path, data, success, failure )

parameters

  • path string

    数据字典中的数据路径,允许使用中文。当路径为多级时,用点号(.)分隔。如果path在数据字典中已有数据,且原有数据是数组,则数组添加一项;如果原有数据不是数组,则报错。

  • data object | array | string | number | boolean

    需要新增的数据

  • success function

    增加数据成功时的回调函数。流程设计后台脚本中无此参数。

  • failure function

    增加数据错误时的回调函数。流程设计后台脚本中无此参数。

examples

var dict = new this.dict({
    //type: 应用类型。可以为process  cms portal service。默认为process。
   type : "cms",
   application : "bulletin", //流程、cms、门户管理的名称、别名、id。引用服务管理的数组字典则忽略该参数。
   name : "bulletindictionary", // 数据字典的名称、别名、id
});
dict.add( "category", { text : "系统公告", value : "system" }, function(data){
   //data 形如
   //{
   //    "id": "80ed5f60-500f-4358-8bbc-b7e81f77aa39" //id为数据字典id
   //}
}, function(xhr){
   //xhr 为 xmlhttprequest
});

对get方法样例的数据字典进行赋值,如下:

var dict = new this.dict({
    //type: 应用类型。可以为process  cms portal service。默认为process。
   type : "cms",
   application : "bulletin", //流程、cms、门户管理的名称、别名、id。引用服务管理的数组字典则忽略该参数。
   name : "bulletindictionary", // 数据字典的名称、别名、id
});
dict.add( "category", { text : "系统公告", value : "system" }, function(data){
   //data 形如
   //{
   //    "id": "80ed5f60-500f-4358-8bbc-b7e81f77aa39" //id为数据字典id
   //}
}, function(xhr, text, error){
   //xhr 为 xmlhttprequest, text 为错误文本, error为error对象
});
    //数据字典的值变为
{
   "category": [
       {
           "enable": true,
           "sequence": 1.0,
           "text": "公司公告",
           "value": "company"
       },
       {
           "enable": "false",
           "sequence": 2.0,
           "text": "部门公告",
           "value": "department"
       },
       {
           "text": "系统公告",
           "value": "system"
       }
   ]
}
 dict.add( "category.2.sequence", 3 );
    //数据字典的值变为
{
   "category": [
       {
           "enable": true,
           "sequence": 1.0,
           "text": "公司公告",
           "value": "company"
       },
       {
           "enable": "false",
           "sequence": 2.0,
           "text": "部门公告",
           "value": "department"
       },
       {
           "sequence" : 3.0,
           "text": "系统公告",
           "value": "system"
       }
   ]
}
dict.add( "archiveoptions", {
   "yes" : "是",
   "no" : "否"
});
    //数据字典的值变为
{
   "category": [
       {
           "enable": true,
           "sequence": 1.0,
           "text": "公司公告",
           "value": "company"
       },
       {
           "enable": "false",
           "sequence": 2.0,
           "text": "部门公告",
           "value": "department"
       },
       {
           "sequence" : 3.0,
           "text": "系统公告",
           "value": "system"
       }
   ],
   "archiveoptions" : {
       "yes" : "是",
       "no" : "否"
   }
}

下面是错误的赋值,如下:

dict.add( "category.3", { text : "系统公告", value : "system" }); //出错,因为不能对数组下标直接赋值
dict.add( "category.1.value", { text : "系统公告" } ); //出错,因为不能对已经存在的非数组路径赋值

source

delete(path, successopt, failureopt)

根据路径删除数据字典的数据。流程设计后台脚本中无此方法。

syntax

dict.delete( path, success, failure )

parameters

  • path string

    数据字典中的数据路径,允许使用中文。当路径为多级时,用点号(.)分隔。如果数据路径不存在,则报错。

  • success function

    删除数据成功时的回调函数。

  • failure function

    删除数据错误时的回调函数。

examples

var dict = new this.dict({
   //type: 应用类型。可以为process  cms portal service。默认为process。
   type : "cms",
   application : "bulletin", //流程、cms的名称、别名、id, 默认为当前应用
   name : "bulletindictionary", //流程、cms、门户管理的名称、别名、id。引用服务管理的数组字典则忽略该参数。
});
dict.delete( "category", function(){
}, function(xhr){
   //xhr 为 xmlhttprequest
});

对example set的数据字典进行赋值,如下:

var dict = new this.dict("bulletindictionary");
dict.delete( "archiveoptions");
//数据字典的值变为
{
   "category": [
       {
           "enable": true,
           "sequence": 1.0,
           "text": "公司公告",
    *            "value": "company"
       },
       {
           "enable": "false",
           "sequence": 3.0,
           "text": "部门公告",
           "value": "department"
       },
       {
           "sequence": 2.0,
           "text": "县级公告",
           "value": "county"
       }
   ]
}
dict.delete( "category.2.sequence", function(data){
   //data 形如
   //{
   //    "id": "80ed5f60-500f-4358-8bbc-b7e81f77aa39" //id为数据字典id
   //}
}, function(xhr){
   //xhr 为 xmlhttprequest
});
//数据字典的值变为
{
   "category": [
       {
           "enable": true,
           "sequence": 1.0,
           "text": "公司公告",
           "value": "company"
       },
       {
           "enable": "false",
           "sequence": 3.0,
           "text": "部门公告",
           "value": "department"
       },
       {
           "text": "县级公告",
           "value": "county"
       }
   ]
}
dict.delete( "category.2");
//数据字典的值变为
{
   "category": [
       {
           "enable": true,
           "sequence": 1.0,
           "text": "公司公告",
           "value": "company"
       },
       {
           "enable": "false",
           "sequence": 3.0,
           "text": "部门公告",
           "value": "department"
       }
   ]
}

下面是错误的删除:

dict.delete( "category_1" ); //出错,因为category_1在数据字典中不存在

source

网站地图