如何获取回调函数的值
//提取数据源gridgetGridByStatement:function(statementId,filterJson,page=1,size=20){
//filterJson格式:{'logic':'逻辑运算:and|or','path':'data数据的路径:$work.title','comparison':'比较运算符:equals|notEquals|like|notLike|greaterThan|greaterThanOrEqualTo|lessThan|lessThanOrEqualTo|range','value':'7月','formatType':'textValue|numberValue|dateTimeValue|booleanValue'}
var bundles=[];
this.xqueryAction.StatementAction.execute(statementId,page,size,filterJson,
function(json){
data = json.data;
bundles=data;
}.bind(this),
function( json ){
data = json.data;
}.bind(this)
);
return bundles;
},
实际结果bundles还是初始值,并不是回调函数里赋值的data
接口默认是异步调用的,您要在外面获取到里面赋值的值,需要改成同步调用,在失败函数后面加一个false参数 本帖最后由 szjazz 于 2024-10-30 11:11 编辑
请问如何变为同步?
让失败函数直接返回false?
getGridByStatement:function(statementId,filterJson,page=1,size=20){
//filterJson格式:{'logic':'逻辑运算:and|or','path':'data数据的路径:$work.title','comparison':'比较运算符:equals|notEquals|like|notLike|greaterThan|greaterThanOrEqualTo|lessThan|lessThanOrEqualTo|range','value':'7月','formatType':'textValue|numberValue|dateTimeValue|booleanValue'}
var bundles=[];
this.xqueryAction.StatementAction.execute(statementId,page,size,filterJson,
function(json){
data = json.data;
bundles=data;
}.bind(this),
function( json ){
data = json.data;
return false;
}.bind(this)
);
alert(JSON.stringify(bundles));
return bundles;
},
测试了下还是返回空值
急等回复 搞定了,明白了,在失败函数的后面,加个false,谢谢!
页:
[1]