This is the structure of nested array:

$scope.History = [
        {
            isCustomer:false,
            userText:"some text",
            options:[]            
        }

The array with data: //The text in DisplayLabel will be the same for all the objects.

$scope.Categories = [
   { "QuestionId": 1, "QuestionName": "Complaint", "DisplayLabel": "what is it?" },
   { "QuestionId": 2, "QuestionName": "Registration", "DisplayLabel": "what is it?" }        
            ];

Desired Array:

$scope.History = [
        {
            isCustomer:false,
            userText:"what is it?",
            options:["Complaint","Registration"]            
        }

Normally I would do this for a 1D array

angular.forEach($scope.Categories, function (value, key) {
$scope.History.push(false,value.DisplayLabel);

Now, how to add items to 'options' for an object.

EDIT: I tried this but no luck. Doesn't display any data

var optionsData = [];
var userText = "";
angular.forEach($scope.Categories, function (value, key) {
optionsData.push(value.QuestionName);
userText = value.DisplayLabel;
        })
        $scope.History.push(false,userText,optionsData);

Related posts

Recent Viewed