samedi 26 novembre 2016

Ember cli format json data from deep nested relationship

I am very new in Ember and also this is my first question after 1 week for researching. Please correct me if I missed something. Currently, I am using Ember and ROR for my backend, I am building the treeview base on ember-cli-jstree. My expected json data for JStree should be looked like this { "text": "TestCycle", "type": "testcycle_parent", "children": [{ "text": "voluptates", "li_attr": { "id": 12 }, "type": "testcycle", "children": [{ "li_attr": { "data-id": 10 }, "text": "quia", "type": "testsuite", "children": [{ "text": "Automation TestCase", "li_attr": { "testsuite-id": 10 }, "type": "automation", "children": [{ "text": "TC-in", "a_attr": { "auto-id": 1, "testsuite-id": 10, "testcycle-id": 12 }, "type": "automation_testcase" } ] }, { "li_attr": { "testsuite-id": 10 }, "text": "Manual TestCase", "type": "manual", "children": [{ "text": "TC-aaa", "a_attr": { "manual-id": 1, "testsuite-id": 10, "testcycle-id": 12 }, "type": "manual_testcase" }, { "text": "TC-bb", "a_attr": { "manual-id": 2, "testsuite-id": 10, "testcycle-id": 12 }, "type": "manual_testcase" } ] } ] } ] } ] } Project model:

name: DS.attr('string'),
description: DS.attr('string'),
testcycles: DS.hasMany('testcycle', {
    embedded: 'always'
}),
testsuites: DS.hasMany('testsuite', {
    embedded: 'always'
}),

Testcycle model:

name: DS.attr('string'),
testsuites: DS.hasMany('testsuite', {
    embedded: 'always'
}),
project: DS.belongsTo('project', {
    embedded: 'always'
}),

Testsuite model:

name: DS.attr('string'),
testcycle: DS.belongsTo('testcycle', {
    embedded: 'always'
}),
project: DS.belongsTo('project', {
    embedded: 'always'
}),
automations: DS.hasMany('automation', {
    embedded: 'always'
}),
manuals: DS.hasMany('manual', {
    embedded: 'always'
})

Automation model:

name: DS.attr('string'),
value: DS.attr('string'),
testsuite: DS.belongsTo('testsuite', {
    embedded: 'always'
})

The question is how can I get deep nested data when user on project page and format the json jstree. The route for project is:

 model: function(params) {
    return this.store.findRecord('project', params.project_id);
},

and the data which i got on project page is

{
"data": {
    "id": "90",
    "type": "projects",
    "attributes": {
        "name": "Grant, Price and Schneider",
        "description": "Cross-platform full-range process improvement"
    },
    "relationships": {
        "testcycles": {
            "data": [{
                    "id": "12",
                    "type": "testcycles"
                }, {
                    "id": "13",
                    "type": "testcycles"
                }
            ]
        },
        "testsuites": {
            "data": [{
                    "id": "10",
                    "type": "testsuites"
                }, {
                    "id": "11",
                    "type": "testsuites"
                }
            ]
        }
    }
}

} many thanks (I am using JSONAPISerializer adapter)!




Aucun commentaire:

Enregistrer un commentaire