Click here to Skip to main content
15,909,193 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
if (result.data) {
               $scope.dropDownListManager.add({ text: 'All', value: 0 });
               for (var i = 0; i < result.data.length; i++) {
                   $scope.dropDownListManager.add({
                       text: result.data[i][1],
                       value: result.data[i][0]
                   });
               }


What I have tried:

<pre> if (result.data) {
                $scope.dropDownListManager.add({ text: 'All', value: 0 });
                for (var i = 0; i < result.data.length; i++) {
                    $scope.dropDownListManager.add({
                        text: result.data[i][1],
                        value: result.data[i][0]
                    });
                }
Posted
Updated 17-Dec-18 6:44am
Comments
Afzaal Ahmad Zeeshan 17-Dec-18 7:38am    
And the problem with the code or logic is?
Chinnu2020 17-Dec-18 7:41am    
I need to use Jquery Map function to load dropdown data

1 solution

By looking at the code, not clear why you need .map, it doesn't look like the code is trying to alter the object persona. it simply get the result from API and bind to the dropdown. Anyway, something like below should work. Refer below link for an example.

JavaScript
$.map( result.data, function( value, key ) {
   $scope.dropDownListManager.add({
                        text: key,
                        value: value
                    });

//  return '';
});

jQuery.map() | jQuery API Documentation[^]

Example:
populate dropdown Example[^]
 
Share this answer
 
Comments
Chinnu2020 17-Dec-18 14:13pm    
is that Jquery Map function will load data in dropdown faster?
Bryian Tan 18-Dec-18 6:57am    
I think performance wise should not make much different. You might need to test it out.
Chinnu2020 18-Dec-18 9:34am    
its not working for me...can you please modify below code and send it
$scope.loadManagerData = function () {
$scope.dropDownListManager = new kendo.data.DataSource();
//Fetch the Managers Dropdown list from the database
$http.get('/MigByManager/GetManagerDropdownList/' + projectId)
.then(function (result) {
if (result.data) {
$scope.dropDownListManager.add({ text: 'All', value: 0 });
for (var i = 0; i < result.data.length; i++) {
$scope.dropDownListManager.add({
text: result.data[i][1],
value: result.data[i][0]
});
}
}
},

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900