Datatable editor with node.js & knex - Access options value with dotted key or rename key

Datatable editor with node.js & knex - Access options value with dotted key or rename key

CapamaniaCapamania Posts: 229Questions: 79Answers: 5

I'm using datatable editor with node.js and knex.js. When rendering a field ... I can add a options list to it like this:

datatable editor node.js using knex.js :

new Field('users.site')
    .options(new Options()
        .table('sites')
        .value('id')
        .label('name')
    );

To access the json I can call the table and look for options:

javascript:

table_users.on( 'xhr', function () {
    var jsonOptions = table_users.ajax.json().options;
    console.log(jsonOptions);
} )

If I output it I get:

console.log

{…}
    "users.site": (4) […]
        0: Object { label: "A", value: "A" }
        1: Object { label: "B", value: "B" }
        2: Object { label: "C", value: "C" }
        3: Object { label: "D", value: "D" }
        length: 4
        <prototype>: Array []
        <prototype>: {…   

... but I'm not able to access the "users.site" array ... when I do this:

table_users.on( 'xhr', function () {
    var jsonOptions = table_users.ajax.json().options;
    console.log(jsonOptions.users.site);
} )      

... I'm getting an error in the console:

TypeError: jsonOptions.users is undefined

Obviously I can call jsonOptions.users.site ... but how can I access those values? Can I rename the options access key for instance? (If its possible to change the key name ... I would only want to change it for the options key ... not for the column key though if possible.)

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    edited January 2019 Answer ✓

    My guess is with this "users.site": (4) […] you would need to access that object using jsonOptions['users.site'].

    Kevin

  • CapamaniaCapamania Posts: 229Questions: 79Answers: 5

    Worked ... thanks!

This discussion has been closed.