djhvscf / bootstrap-table-flatJSON

Plugin to flat the JSON object. Extension for Bootstrap-table
MIT License
12 stars 7 forks source link

Feature request: exposed expandJSON method #5

Open jtrumbull opened 9 years ago

jtrumbull commented 9 years ago

@djhvscf: I forked this repository and was going to create some PRs. Didn't want to get to far if this is something that you are working on -or did't want in the extension.

I don't have any working code yet, but the function would reverse the results of flatJSON, to the data's native JSON format.

$.fn.bootstrapTable.methods.push('expandJSON');

Usage:

// On Array of Objects
$('#table').bootstrapTable('expandJSON', [
    {
        "user.name": "jtrumbull",
        "user.mood": "bored",
        "user.array.0.key1": "a"
        "user.array.1.key1": "b"
        "user.array.3.key1": "c"
    },
    {...},
    {...}
]);

// or on single Object
$('#table').bootstrapTable('expandJSON', {...});

Would produce:

[
    {
        "user": {
            "name": "jtrumbull",
            "mood": "bored",
            "array": [
                { "key1": "a" },
                { "key1": "b" },
                { "key1": "c" }
            ]
        }
    },
    {...},
    {...}
]
djhvscf commented 9 years ago

Go ahead with PRs and any other change that you want to do.. I would like to improve this extension