mirror of
https://github.com/tenrok/vue-json-viewer.git
synced 2026-06-23 20:40:38 +03:00
add an option to enable key sorting before display
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<j-icon v-if="!keyName" :type="value ? 'arrow-down-b' : 'arrow-up-b'" @click.stop="toggle"></j-icon>
|
<j-icon v-if="!keyName" :type="value ? 'arrow-down-b' : 'arrow-up-b'" @click.stop="toggle"></j-icon>
|
||||||
<span>{</span>
|
<span>{</span>
|
||||||
<template v-if="Object.keys(ordered).length">
|
<template v-if="Object.keys(ordered).length">
|
||||||
<json-box v-show="value" v-for="(v, k) in ordered" :key="k" :key-name="k" :value="v"></json-box>
|
<json-box v-show="value" v-for="(v, k) in ordered" :sort-keys="sortKeys" :key="k" :key-name="k" :value="v"></json-box>
|
||||||
<span v-show="!value" class="node-ellipsis">...</span>
|
<span v-show="!value" class="node-ellipsis">...</span>
|
||||||
</template>
|
</template>
|
||||||
<span>}</span>
|
<span>}</span>
|
||||||
@@ -22,14 +22,14 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
ordered () {
|
ordered () {
|
||||||
const ordered = {};
|
if (!this.sortKeys) {
|
||||||
if (this.sortKeys) {
|
return this.jsonValue;
|
||||||
Object.keys(this.jsonValue).sort().forEach(key => {
|
|
||||||
ordered[key] = this.jsonValue[key];
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
ordered = this.jsonValue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ordered = {};
|
||||||
|
Object.keys(this.jsonValue).sort().forEach(key => {
|
||||||
|
ordered[key] = this.jsonValue[key];
|
||||||
|
});
|
||||||
return ordered;
|
return ordered;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user