在SharePoint中的executeQueryAsync中从Success方法检索值

时间:2019-05-02 15:01:07

标签: javascript sharepoint-online

标题很好地说明了我的问题。我只是想从.executeQueryAsync中的成功函数中检索值。每当我尝试获取在我称为_returnParam的返回变量中提供的数据时,我都会发现它没有检索我需要的值。该代码肯定会突出显示我显然找不到的问题。提前致谢!

function retrieveIdFood(nom_food,type){
var _returnParam='hello';

var clientContext = new SP.ClientContext();
  var oListii = clientContext.get_web().get_lists().getByTitle(type);

    var camlQuery = new SP.CamlQuery();

    this.collListItem = oListii.getItems(camlQuery);

    clientContext.load(collListItem);


    clientContext.executeQueryAsync(
    Function.createDelegate(this,function(){_returnParam=onQueryRetrieveIdFoodYes(nom_food);}),Function.createDelegate(this, this.onQueryRetrieveIdFoodNo));
  alert(_returnParam);// _returnParam contains the value "undefined"
  fonctionVoid(); // just a function that returns 0
return _returnParam;
 }

onQuerySuccess方法:

function onQueryRetrieveIdFoodYes(nom_food){
 var _returnParam='hello';
var listItemInfo = '';

   var listItemEnumerator = collListItem.getEnumerator();
    while (listItemEnumerator.moveNext()) {

       var oListeeeItem  = listItemEnumerator.get_current();

if(oListeeeItem.get_item('Title').toString()==nom_food)
 {

_returnParam=oListeeeItem.get_item('ID');
 alert ('the value of returnParam is: '+ _returnParam);//here, return param has the id that i want to retrieve
 fonctionVoid(); // just a function that returns 0
 return _returnParam;
 }


 }

}

0 个答案:

没有答案