2
votes

I'm not using RESTAdapter so I create Ember Object and using reopenClass method and jquery ajax function for ajax requesting and the code is:

OlapApp.Dimenssions = Ember.Object.extend({});
OlapApp.Dimenssions.reopenClass({
measure:Ember.A(),
find:function(cubeUniqueName){
    var c = Ember.A();
    var xhr = $.ajax({
        type: 'POST',
        dataType: 'json',
        contentType: 'application/json',
        url: 'http://localhost:9095/service.asmx/getDimension',
        data: '{"cubeUniqueName":"'+cubeUniqueName+'"}',
        success: function(response) {
            var data = JSON.parse(response.d);

            $.each(data.hierarchies,function(i,v) {
             c.pushObject(OlapApp.Dimenssions.create(v));
            });
            console.log(c);
        }
    });
    return c;
}
});

when OlapApp.Dimenssions.find() called the server response a json like this:

{
"uniqueName": "[Customers] = [Database].[Cube 2]",
"name": "Customers",
"caption": "Customers",
"dimensionUniqueName": null,
"description": "Description",
"levelUniqueName": null,
"hierarchyUniqueName": null,
"visible": true,
"hierarchies": [
    {
        "uniqueName": "[Customers]",
        "name": "Customers",
        "caption": "Customers",
        "dimensionUniqueName": "[Customers]",
        "levels": [
            {
                "uniqueName": "[Customers].[(All)]",
                "name": "(All)",
                "caption": "(All)",
                "description": "Description",
                "hierarchyUniqueName": "[Customers]",
                "dimensionUniqueName": "[Customers]",
                "visible": true
            },
            {
                "uniqueName": "[Customers].[Country]",
                "name": "Country",
                "caption": "Country",
                "description": "Description",
                "hierarchyUniqueName": "[Customers]",
                "dimensionUniqueName": "[Customers]",
                "visible": true
            }
        ]
    }
]
}

the first problem is here that I can't push json corectly in c arrary so I try to create a model for this and the model code is:

OlapApp.RootMembers = DS.Model.extend({

id:DS.attr("number"),
uniqueName:DS.attr('string'),
name:DS.attr('string'),
caption:DS.attr('string'),
dimensionUniqueName:DS.attr('string'),
description:DS.attr('string'),
levelUniqueName:DS.attr('string'),
hierarchyUniqueName:DS.attr('string')

});

OlapApp.Levels = DS.Model.extend({

id:DS.attr("number"),
uniqueName:DS.attr('string'),
name:DS.attr('string'),
caption:DS.attr('string'),
hierarchyUniqueName:DS.attr('string'),
dimensionUniqueName:DS.attr('string'),
visible:DS.attr('boolean'),
description:DS.attr('string')

});

OlapApp.Hierarchies = DS.Model.extend({

id:DS.attr("number"),
uniqueName:DS.attr('string'),
name:DS.attr('string'),
caption:DS.attr('string'),
dimensionUniqueName:DS.attr('string'),
levels:DS.hasMany(OlapApp.Levels,{embedded:always}),
rootMembers:DS.hasMany(OlapApp.RootMembers,{embedded:always})

});

you can see real json that returned form server here

but how can I map this json to these model ? if I can't map to model can I map nested json to Ember.Object.

2

2 Answers

0
votes
this.set('yourModelClass', yourArray.props);

This should do the trick as you said that you have all the json data in Array 'C'

-1
votes

i can fix my problem with this line of code :

var data = JSON.parse(response.d);
c.pushObject(Ember.Object.create(data));