在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:josdejong/svelte-jsoneditor开源软件地址:https://github.com/josdejong/svelte-jsoneditor开源编程语言:TypeScript 50.5%开源软件介绍:svelte-jsoneditorA web-based tool to view, edit, format, transform, and validate JSON The library is written with Svelte, but can be used in any framework (React, Vue, Angular, plain JavaScript). Features
InstallInstall via npm:
Remark: you may notice that UseExamples
Svelte usageCreate a JSONEditor with two-way binding <script>
import { JSONEditor } from 'svelte-jsoneditor'
let content = {
text: undefined, // used when in text mode
json: {
array: [1, 2, 3],
boolean: true,
color: '#82b92c',
null: null,
number: 123,
object: { a: 'b', c: 'd' },
string: 'Hello World'
}
}
</script>
<div>
<JSONEditor bind:content />
</div> Or one-way binding: <script>
import { JSONEditor } from 'svelte-jsoneditor'
let content = {
text: undefined, // used when in text mode
json: {
greeting: 'Hello World'
}
}
function handleChange(updatedContent, previousContent, patchResult) {
// content is an object { json: JSONData } | { text: string }
console.log('onChange: ', updatedContent, previousContent, patchResult)
content = updatedContent
}
</script>
<div>
<JSONEditor {content} onChange="{handleChange}" />
</div> Standalone bundle (use in React, Vue, Angular, plain JavaScript, ...)The library provides a standalone bundle of the editor which can be used in any browser environment and framework. In a framework like React, Vue, or Angular, you'll need to write some wrapper code around the class interface. Browser example loading the ES module: <!DOCTYPE html>
<html lang="en">
<head>
<title>JSONEditor</title>
</head>
<body>
<div id="jsoneditor"></div>
<script type="module">
import { JSONEditor } from 'svelte-jsoneditor/dist/jsoneditor.js'
let content = {
text: undefined,
json: {
greeting: 'Hello World'
}
}
const editor = new JSONEditor({
target: document.getElementById('jsoneditor'),
props: {
content,
onChange: (updatedContent, previousContent, patchResult) => {
// content is an object { json: JSONData } | { text: string }
console.log('onChange', updatedContent, previousContent, patchResult)
content = updatedContent
}
}
})
// use methods get, set, update, and onChange to get data in or out of the editor.
// Use updateProps to update properties.
</script>
</body>
</html> APIconstructorSvelte component: <script>
import { JSONEditor } from 'svelte-jsoneditor'
</script>
<div>
<JSONEditor {content} />
</div> JavasScript class: import { JSONEditor } from 'svelte-jsoneditor/dist/jsoneditor.js'
const editor = new JSONEditor({
target: document.getElementById('jsoneditor'),
props: {
content,
onChange: (updatedContent, previousContent, patchResult) => {
// content is an object { json: JSONData } | { text: string }
console.log('onChange', updatedContent, previousContent, patchResult)
}
}
}) properties
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论