JS SDK API.docx

范例:

以常见的省市县三级联动举例,如下代码配置在在省下拉框的onChange事件中的JsAction中

let currentValue = payload.changedValue; //获取当前下拉框的值
if ( !currentValue) { 
  return;
} 

let body = {};  //定义请求restAPI的body
let parentKeys = [];
body.entityName = "com.open_care.sys.OcAddress";
body.fieldName = "city";
body.relationFieldName = "parentKey";
parentKeys.push(currentValue);
body.parentKeys = parentKeys;

function getResponseHandler(response) { 
    let targetComponent = ocWindow.getComponentByName('Form1_city');  //根据componentName=Form1_city找到市组件
  let value = response.data;  //获得返回的数据
  targetComponent.setOptions(value); //将返回的结果放入市下拉框中
  targetComponent.setValueOfFirstOption(); //默认显示下拉框的第一个值

  return; 
} 

OC.restPostApiCall('/getValueOptions', {}, body, getResponseHandler) //调用后端RestAPI,getResponseHandler为回调函数