1
我的前端有backbone.js和require.js,我的ace編輯器給我一個錯誤,說明我的元素不在容器元素上。我認爲我應該等待,直到準備好或類似的東西。追加元素骨幹後元素不存在
我的視圖代碼:
define(['jquery', 'underscore', 'backbone', 'text!templates/txtEditor.html'],function($, _, Backbone, textEditorTemplate){
function get (aceInst) {
return aceInst.getSession();
}
var txtEditorView = Backbone.View.extend({
el: 'kitcube-console',
appendElem: $('#kitcube-container'),
template: _.template('#txtEditorTemplate'),
render: function(){
editor.resize();
$('#kitcube-console').style.fontSize = '14px';
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/yaml");
},
initialize: function() {
var data = {};
var compiledTemplate = _.template(textEditorTemplate, data);
this.appendElem.append(compiledTemplate);
//console.log(_.template(textEditorTemplate, {}));
if (!document.getElementById(this.el)) {
console.log('not inserted yet');
}
var editor = ace.edit(this.el);
this.render();
}
});
// 'jquery', 'underscore', 'backbone' will not be accessible in the global scope
return txtEditorView;
// What we return here will be used by other modules
});
我的模板:
<div id="kitcube-console">tab1:
element0:
name: circle
xcoord: 1
ycoord: 5
element1:
name: square
xcoord: 5
ycoord: 10
tab2:
element0:
name: circle
xcoord: 1
ycoord: 5
element1:
name: square
xcoord: 5
ycoord: 10
</div>
錯誤:事先
謝謝,順便說一下,ace編輯器的編輯方法只能得到沒有#符號的字符串。 [求助鏈路(http://ace.c9.io/#nav=embedding) –