Skip to content

Commit 5834394

Browse files
authored
Merge pull request #199 from leezng/dev
release 2.2.2
2 parents 0dbfb68 + 63e638d commit 5834394

File tree

3 files changed

+86
-5
lines changed

3 files changed

+86
-5
lines changed

example/Basic.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272
>
7373
<template v-if="state.useRenderNodeKeySlot" #renderNodeKey="{ node, defaultKey }">
7474
<template v-if="node.key === 'title'">
75-
<a>"{{ node.key }}":</a>
75+
<a>"{{ node.key }}"</a>
7676
</template>
77-
<template v-else>{{ defaultKey }}:</template>
77+
<template v-else>{{ defaultKey }}</template>
7878
</template>
7979

8080
<template v-if="state.useRenderNodeValueSlot" #renderNodeValue="{ node, defaultValue }">

src/components/TreeNode/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export default defineComponent({
122122

123123
return render
124124
? render({ node: props.node, defaultKey: prettyKey.value || '' })
125-
: <span class="vjs-key">{`${prettyKey.value}: `}</span>;
125+
: prettyKey.value;
126126
};
127127

128128
const isMultiple = computed(() => props.selectableType === 'multiple');
@@ -235,7 +235,12 @@ export default defineComponent({
235235
{props.showIcon && <Carets nodeType={node.type} onClick={handleIconClick} />}
236236
</div>
237237

238-
{node.key && renderKey()}
238+
{node.key && (
239+
<span class="vjs-key">
240+
{renderKey()}
241+
<span>:</span>
242+
</span>
243+
)}
239244

240245
<span>
241246
{node.type !== 'content' && node.content ? (

src/utils/index.ts

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export function jsonFlatten(
7676
keys.map((objKey, idx, arr) =>
7777
jsonFlatten(
7878
(data as Record<string, JSONDataType>)[objKey],
79-
objKey.includes('.') ? `${path}["${objKey}"]` : `${path}.${objKey}`,
79+
/^[a-zA-Z_]\w*$/.test(objKey) ? `${path}.${objKey}` : `${path}["${objKey}"]`,
8080
level + 1,
8181
{
8282
key: objKey,
@@ -171,3 +171,79 @@ export function stringToAutoType(source: string): unknown {
171171
}
172172
return value;
173173
}
174+
175+
// function jsonFlattenNext(data: JSONDataType, path = 'root'): JSONFlattenReturnType[] {
176+
// function test(content: unknown, path: string, level: number, options: JSONFlattenOptions) {
177+
// const { type = 'content', key, index, showComma, length } = options || {};
178+
// return {
179+
// content,
180+
// level,
181+
// key,
182+
// index,
183+
// path,
184+
// showComma,
185+
// length,
186+
// type,
187+
// };
188+
// }
189+
190+
// let endObj = {} as Record<string, unknown>;
191+
// let i = 0;
192+
// let output: any = [data];
193+
// let startArr = [];
194+
// while (output.length || endObj[i]) {
195+
// if (i && endObj[i]) {
196+
// const k = endObj[i];
197+
// delete endObj[i];
198+
// startArr.push(k);
199+
// i++;
200+
// } else {
201+
// const now = output.shift();
202+
// if (Array.isArray(now)) {
203+
// startArr.push(
204+
// test('[', path, 0, {
205+
// type: 'arrayStart',
206+
// showComma: false,
207+
// length: now.length,
208+
// }),
209+
// );
210+
// output = now.concat(output);
211+
// Object.keys(endObj)
212+
// .sort((a, b) => Number(b) - Number(a))
213+
// .forEach(id => {
214+
// endObj[Number(id) + now.length + 1] = endObj[id];
215+
// delete endObj[id];
216+
// });
217+
// endObj[i + now.length] = ']';
218+
// } else if (typeof now === 'object') {
219+
// startArr.push(
220+
// test('{', path, 0, {
221+
// type: 'objectStart',
222+
// showComma: false,
223+
// length: Object.keys(now).length,
224+
// }),
225+
// );
226+
// output = Object.keys(now)
227+
// .map(key => now[key])
228+
// .concat(output);
229+
// Object.keys(endObj)
230+
// .sort((a, b) => Number(b) - Number(a))
231+
// .forEach(id => {
232+
// endObj[Number(id) + Object.keys(now).length + 1] = endObj[id];
233+
// delete endObj[id];
234+
// });
235+
// endObj[i + Object.keys(now).length] = '}';
236+
// } else {
237+
// startArr.push(
238+
// test(now, path, 0, {
239+
// type: 'content',
240+
// showComma: false,
241+
// length: 0,
242+
// }),
243+
// );
244+
// }
245+
// }
246+
// }
247+
248+
// return startArr as any;
249+
// }

0 commit comments

Comments
 (0)