Convert dimension to JSON


#1

Hi,

How can i convert a dimension to the following format ?

[CODE]

$scope.links = [
{
text: ‘Menu Item 1’,
url: ‘#’,
submenu: [
{
text: ‘Sub-menu Item 4’,
url: ‘#’,
},{
text: ‘Sub-menu Item 5’,
url: ‘#’,

            }
        ]
    },{
        text: 'Menu Item 2',
        url: '#',
        submenu: [
            {
                text: 'Sub-menu Item 6',
                url: '#',
            },{
                text: 'Sub-menu Item 7',
                url: '#',

            }
        ]
    },{
        text: 'Menu Item 3',
        url: '#',
        submenu: [
            {
                text: 'Sub-menu Item 8',
                url: '#',
            },{
                text: 'Sub-menu Item 9',
                url: '#',

            }
        ]
    }
];

[/CODE]


#2

I got the result that I need. Is there a neater way of doing this ?

[CODE]

$scope.mdxPage =‘SELECT NON EMPTY {[CW Canvas Menu].[Menu]} ON ROWS, NON EMPTY {[}ElementAttributes_CW Canvas Menu].Members} ON COLUMNS FROM [}ElementAttributes_CW Canvas Menu]’;
$tm1Ui.cubeExecuteMdx($scope.instance, $scope.mdxPage).then(function(data){
var Elements = data.Axes[1].Tuples;
$scope.arrayMenu = [];
$scope.arraySubMenu = [];
$scope.htmlPage =[];
$scope.htmlPageLength =Elements.length;

for(i=0;i<Elements.length;i++){
    $scope.htmlPage[i] = {};
	$scope.htmlPage[i].Name = data.Axes[1].Tuples[i].Members[0].Name; 
	$scope.htmlPage[i].Caption = data.Axes[1].Tuples[i].Members[0].Attributes.Caption; 
	$scope.htmlPage[i].Label = data.Axes[1].Tuples[i].Members[0].Attributes.Label; 
	$scope.htmlPage[i].Link = data.Axes[1].Tuples[i].Members[0].Attributes['Link']; 
	$scope.htmlPage[i].Level = data.Axes[1].Tuples[i].Members[0].Attributes['Level']; 


    if($scope.htmlPage[i].Level  == 1){
        if(i!=0){
            $scope.Menu = 
            {
                "text": $scope.Name,
                "url": $scope.Link,
                "level":$scope.Level,
                "submenu" : $scope.arraySubMenu 
            };            
            $scope.arrayMenu.push($scope.Menu);
            $scope.arraySubMenu = [];

        }
        $scope.Name = $scope.htmlPage[i].Name;
        $scope.Link = $scope.htmlPage[i].Link;
        $scope.Level = $scope.htmlPage[i].Level;
    }else if($scope.htmlPage[i].Level  == 0){
        $scope.subMenu = 
        {
            "text": $scope.htmlPage[i].Name,
            "url": $scope.htmlPage[i].Link,
            "level":$scope.htmlPage[i].Level,
        };
        $scope.arraySubMenu.push($scope.subMenu);
        
    }
}
            $scope.Menu = 
            {
                "text": $scope.Name,
                "url": $scope.Link,
                "level":$scope.Level,
                "submenu" : $scope.arraySubMenu 
            };            
            $scope.arrayMenu.push($scope.Menu);

});
[/CODE]