2015-05-16 33 views
2

我试图在隐藏容器块时设置ace编辑器内容。如何在容器块隐藏时设置ace-editor内容?

我不能相同。

这里是我努力 http://jsfiddle.net/U5JtP/408/

这里是我的代码:

var editor = ace.edit("editor"); 
editor.setTheme("ace/theme/monokai"); 
editor.getSession().setMode("ace/mode/javascript"); 

$('#hide').click(function(){ 
    $('.panel-body').hide(); 
    $('#hide').hide(); 
    $('#Show').hide(); 
    $('#setValue').show(); 
}); 

$('#Show').click(function(){ 
    $('.panel-body').show(); 
    $('#setValue').hide(); 
    $('#Show').hide(); 
    $('#hide').show(); 
}); 

$('#setValue').click(function(){ 
    editor.getSession().setValue('function foo(items) {}'); 
    $('.panel-body').hide(); 
    $('#setValue').hide(); 
    $('#Show').show(); 
    $('#hide').hide(); 
}); 

////// -------------------------- Click on Hide -> SetValue -> Show 
/// Why ace editor did not updated the content and how to update in such scenario? 

你能不能使这项工作?

回答

0

正在设置该值,但编辑器未更新。所以你必须使用updateFull() which is a method of ace editor's VirtualRenderer手动调用它。

这是怎样的方法可以调用

editor.renderer.updateFull(); 

更新setValue方法来这样的事情

$('#setValue').click(function(){ 
    editor.getSession().setValue('function foo(items) {}'); 
    editor.renderer.updateFull(); 
    $('.panel-body').hide(); 
    $('#setValue').hide(); 
    $('#Show').show(); 
    $('#hide').hide(); 
}); 

这里是更新的演示http://jsfiddle.net/dhirajbodicherla/U5JtP/410/; PS:如果在#setValue点击处理程序中使用updateFull,我发现在更新编辑器时会稍微延迟一点。如果在#show点击处理程序中使用updateFull,则不会有延迟。

+0

我确实考虑你的答案,但我正在寻求更好的答案。这将在ace中进行一些内部配置。我不想手动调用'updateFull'。 – codeofnode