我的網頁上有一個ACE代碼編輯器,當下拉選項被更改時,它應該用一個新值進行刷新。目前,當通過下拉菜單的「onchange」調用該功能時,會出現警告消息。但是,我無法更改ACE代碼編輯器中顯示的內容。如何更改jquery-ace代碼編輯器文本區域的值?
我正在使用這個jQuery插件 - http://cheef.github.io/jquery-ace/。它沒有太多的文檔。
<div class="container">
<div class="column-left">
<h2>Sources</h2>
<%= collection_select(:source, :select_source, Source.all, :id, :name, options = {include_blank: "Please select a source..."}, html_options = {:onchange => "updateTextArea()"}) %>
</div>
<div class="column-center">
<h2>Code</h2>
<textarea id="txtbox1" class="my-code-area" rows="20" style="width: 100%">awaiting source...</textarea>
</div>
</div>
<script>
$('.my-code-area').ace({
theme: 'twilight',
lang: 'ruby'
})
var decorator = $('.my-code-area').data('ace');
var aceInstance = decorator.ace;
function updateTextArea() {
var text = "source changed"
alert(text);
aceInstance.edit("txtbox1").setValue("source changed");
}
</script>
嘗試將setValue()替換爲值() –
這沒有幫助。它實際上似乎是「編輯」本身是有問題的 - 未捕獲TypeError:無法讀取未定義的屬性'編輯'。所以我可能會錯誤地認爲aceInstance等同於var editor = ace.edit(「editor」); (https://ace.c9.io/#nav=embedding) – A21
在沙盒中創建示例plz –