From d49518a9badfb3342bbce09b3f8a69c738f3078f Mon Sep 17 00:00:00 2001 From: jos Date: Mon, 6 Aug 2018 14:39:21 +0200 Subject: [PATCH] Describe new methods `update` and `updateText` in the docs --- HISTORY.md | 6 ++++++ docs/api.md | 32 +++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index a5072bf..4f4c55c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,12 @@ https://github.com/josdejong/jsoneditor +## not yet released, version 5.20.0 + +- Implemented new methods `update` and `updateText`, which maintain the state + of the editor (expanded nodes, search, selection). + + ## 2018-08-02, version 5.19.2 - Fixed #558: scrolling to search results and automatically scrolling up/down diff --git a/docs/api.md b/docs/api.md index f9b1354..3e5debc 100644 --- a/docs/api.md +++ b/docs/api.md @@ -50,7 +50,7 @@ Constructs a new JSONEditor. - `{function} onChange` - Set a callback function triggered when the contents of the JSONEditor change. Called without parameters. Will only be triggered on changes made by the user, not in case of programmatic changes via the functions `set` or `setText`. + Set a callback function triggered when the contents of the JSONEditor change. Called without parameters. Will only be triggered on changes made by the user, not in case of programmatic changes via the functions `set`, `setText`, `update`, or `updateText`. - `{function} onEditable` @@ -354,6 +354,8 @@ Get the current selected text with the selection range, Only applicable for mode #### `JSONEditor.set(json)` Set JSON data. +Resets the state of the editor (expanded nodes, search, selection). +See also `JSONEditor.update(json)`. *Parameters:* @@ -441,6 +443,34 @@ Set text selection for a range, Only applicable for mode 'text' and 'code'. Position for selection end +#### `JSONEditor.update(json)` + +Replace JSON data when the new data contains changes. +In modes `tree`, `form`, and `view`, the state of the editor will be maintained (expanded nodes, search, selection). +See also `JSONEditor.set(json)`. + +*Parameters:* + +- `{JSON} json` + + JSON data to be displayed in the JSONEditor. + +#### `JSONEditor.updateText (json)` + +Replace text data when the new data contains changes. +In modes `tree`, `form`, and `view`, the state of the editor will be maintained (expanded nodes, search, selection). +See also `JSONEditor.setText(json)`. + +This method throws an exception when the provided jsonString does not contain +valid JSON and the editor is in mode `tree`, `view`, or `form`. + +*Parameters:* + +- `{String} jsonString` + + Contents of the editor as string. + + ### Examples A tree editor: