codemirror编辑器在单击之前不会加载内容

v6ylcynt  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(248)

我正在尝试使用许多按钮在引导模式中的codemirror编辑器中显示不同的值。但是编辑器的内容直到我点击它才更新!
我是这样玩的:

$(document).ready(function() {

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  matchBrackets: true,
  autoCloseBrackets: true,
  mode: "application/ld+json",
  lineWrapping: true,
  lineNumbers: true,
  readOnly: true,
  autoRefresh: true
});

    //$('body').on('click', 'input.ajust', function (e) {
$('input.ajust').click(function (e) {
        var tagId = $(this).attr('id');
        var jsonInput;

        var mymodal = $('#myModal');

  switch (tagId) {

    case 'mazigh':
      //var url = "data/input/exposure/input.json";  
      //$.getJSON(url, function (data) {
        editor.getDoc().setValue(JSON.stringify('MAZIGH', null, "\t")); 
        editor.refresh();
        setTimeout(function() {
            editor.refresh();
        },1);
      //});
            break;

    case 'takfa': 
      //var url = "data/input/unpaid/input.json";  
      //$.getJSON(url, function (data) {
        editor.getDoc().setValue(JSON.stringify('TAKFA', null, "\t"));  
        editor.refresh();
        setTimeout(function() {
            editor.refresh();
        },1);
      //});
            break;

          default:
            console.log('Sorry, we are out.');
        }

  editor.refresh();
        mymodal.modal('show');//.trigger("change");         

    });
    editor.refresh();

} );
我创建了这个jsfiddle来显示这个行为
https://jsfiddle.net/s91mvb2p/43/

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题