1

I'm trying to create a drop down menu using DexExpress in jQuery with SharePoint REST API. I get the values from the REST call in the console, but I'm having issues trying to display these values in the actual dropdown. The values that I'm trying to get are in a SharePoint list. Please see my code below:

    $(function() {
    var formCo = $("#form").dxForm({
        formData: formCo,
        colCount: 2,
        items: [{
            {
                dataField:"DropdownField",
                itemType:"simple",
                editorType:"dxSelectBox",
                editorOptions: {  
                    items: [
                       function items(){
                       
                           $.ajax({
                               url: url,
                               type: "GET",
                               headers: {
                                   "Accept":"application/json;odata=verbose",
                                   "contentType": "application/json;odata=verbose"
                               },
                               success:success,
                               error: error
                               
                           });
                                                                         
                           function success(data){ 
                                var dataresults = data.d.results;
                                var jsonString  = JSON.stringify(dataresults);
                                var parsedData= JSON.parse(jsonString);
            
                               for(var i = 0; i < parsedData.length; i++){
                                   //Console log displays Name value
                                   console.log(parsedData[i]['Name']);
            
                               }
                                
                           }
                           
                           function error(){
                              //console.error();
                             
            
                           }
                       }

                    ] 
                    
                }  
            }
        }]
    })
})

1 Answer 1

0

I am not an expert at devExpress, but to me, it does not seem right that you pass a function to the items array like so:

editorOptions: {  
 items: [ function items(){  ...  ]         
 ...
}     
  

I think, you need first to get your SharePoint list items and extract Names from them like so:

let names = data.d.results.map(item => item["Name"])

Then pass these names to devExpress like so:


editorOptions: {  
  items: names ,
  ...
}  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.