josdejong/jsoneditor

Reevaluate "onEditable"

Open

#1,386 建立於 2021年11月8日

在 GitHub 查看
 (4 留言) (0 反應) (0 負責人)JavaScript (2,034 fork)batch import
featurehelp wanted

倉庫指標

Star
 (10,781 star)
PR 合併指標
 (平均合併 15小時 36分鐘) (30 天內合併 3 個 PR)

描述

I want to use the "code" or "tree" modes for viewing JSON in readonly mode. However, I want to be able to switch the editor into read/write mode dynamically. At the moment "onEditable" is not reevaluated - can I force JSONEditor to reevaluate whether the JSON can be edited? The only method I've found is to switch mode and then back again - but this comes with its own problems (like cursor location changing, tree collapsing).

        const options = {
            mode: 'code',
            modes: ['code', 'form', 'text', 'tree', 'view', 'preview'],
            onEditable: function () {
                return self.editJSON; <-- this can change dynamically.
            }
        };
        this.jsoneditor = new JSONEditor(container, options);

Perhaps something like?:

this.jsoneditor.reevaluateOnEditable();

Thanks, -Neil

貢獻者指南