Skip to main content
15-Moonstone
January 17, 2022
Solved

fill select widget with for loop

  • January 17, 2022
  • 1 reply
  • 1440 views

I want to fill the 

$scope.view.wdg["select-1"].list

with a for loop.

just like i can do with the following method. 

var title = []; for(var i = 0; i < array.length; i++) { title[i] = { name: array[i], value: i+1 }; }

 

How can I do?

Best answer by sgreywilson

both approaches are working and your code show work - not sure what is not working for you 

 

$scope.colors = function () {

        var listOfColors = [
              {display: "Red",value: "red"},
              {display: "Green",value: "green"},
              {display: "Blue",value: "blue"}
       ]

        $scope.view.wdg.colorSelector.list = title;
}

$scope.$on("$ionicView.afterEnter", function (event) {
$scope.view.wdg["colorSelector"].list = title;
});

// or 

$scope.$on('modelLoaded', function (evt, arg) {
     $scope.colors();

});

1 reply

14-Alexandrite
January 17, 2022

Hi,

you can do it like this:

var array = ["a","b","c"]
var title = []; 
for(var i = 0; i < array.length; i++)
{ title[i] = { display: array[i], value: i+1 }; }
$scope.$on("$ionicView.afterEnter", function (event) {
$scope.view.wdg["select-1"].list = title;
});
16-Pearl
January 17, 2022

both approaches are working and your code show work - not sure what is not working for you 

 

$scope.colors = function () {

        var listOfColors = [
              {display: "Red",value: "red"},
              {display: "Green",value: "green"},
              {display: "Blue",value: "blue"}
       ]

        $scope.view.wdg.colorSelector.list = title;
}

$scope.$on("$ionicView.afterEnter", function (event) {
$scope.view.wdg["colorSelector"].list = title;
});

// or 

$scope.$on('modelLoaded', function (evt, arg) {
     $scope.colors();

});