范例:
以常见的省市县三级联动举例,如下代码配置在在省下拉框的onChange事件中的JsAction中
Code Block | ||
---|---|---|
| ||
var currentValue = payload.changedValue; //获取当前下拉框的值
if ( !currentValue) {
return;
}
var body = {}; //定义请求restAPI的body
var parentKeys = [];
body.entityName = "com.open_care.sys.OcAddress";
body.fieldName = "city";
body.relationFieldName = "parentKey";
parentKeys.push(currentValue);
body.parentKeys = parentKeys;
function getResponseHandler(response) {
var targetComponent = ocWindow.getComponentByName('Form1_city'); //根据componentName=Form1_city找到市组件
var value = response.data; //获得返回的数据
targetComponent.setOptions(value); //将返回的结果放入市下拉框中
targetComponent.setValueOfFirstOption(); //默认显示下拉框的第一个值
return;
}
OC.restPostApiCall('/getValueOptions', {}, body, getResponseHandler) //调用后端RestAPI,getResponseHandler为回调函数 |
表格中某一列变为超链接,在Table的onCreate事件中配置JS Action
ocWindow.getComponentByName('Table1').addColumnForHyperLink('vendor_code'); // vendor_code 指Column的DataIndex