我在我的ExtJS
應用程序中使用CodeMirror
。我這樣做:如何將codemirror實例調整到父對象的完整高度?
Ext.create('Ext.container.Viewport',{
layout:'border',
items:[{
region:'center',
layout:'fit',
border:false,
dockedItems:[{
xtype:'toolbar',
items:[{
xtype:'button',
text:'push me!'
}]
}],
html:'<textarea name="code" id="code"></textarea>',
listeners:{
render:function(){
CodeMirror.fromTextArea(document.getElementById("code"),{
lineNumbers:true,
//fullScreen:true,
mode:{name:'javascript',globalVars:true}
});
}
}
}]
});
問題是textarea
有一些固定的高度,在庫中定義。因此,儘管我添加了width
和height
參數,或者將style:height:100%
添加到元素,但它沒有任何作用。如果我使用fullScreen
選項,那麼我的textarea
甚至會將toolbar
隱藏在頂部。
編輯
我做到了,用css:
.CodeMirror {
width: 100% !important;
height: 100% !important;
}
雖然,我發現在圖書館中的錯誤。如果您將光標放在textarea
裏面的最後一行,並輸入Enter
,那麼高於textarea
的元素將被破壞。
編輯。完整的測試用例
<html>
<head>
<style type="text/css">
body {
margin: 0;
padding: 0;
}
.CodeMirror {
width: 100% !important;
height: 100% !important;
}
</style>
<link rel="stylesheet" type="text/css" href="/static/ext-5.0.1/packages/ext-theme-classic/build/resources/ext-theme-classic-all.css">
<link rel="stylesheet" type="text/css" href="/static/app/pages/lib/js/codemirror-4.7/lib/codemirror.css">
<link rel="stylesheet" type="text/css" href="/static/app/pages/lib/js/codemirror-4.7/addon/display/fullscreen.css">
<script type="text/javascript" src="/static/ext-5.0.1/build/ext-all.js"></script>
<script type="text/javascript" src="/static/ext-5.0.1/build/packages/ext-locale/build/ext-locale-ru.js"></script>
<script type="text/javascript" src="/static/app/pages/lib/js/codemirror-4.7/lib/codemirror.js"></script>
<script type="text/javascript" src="/static/app/pages/lib/js/codemirror-4.7/mode/javascript/javascript.js"></script>
<script type="text/javascript" src="/static/app/pages/lib/js/codemirror-4.7/addon/display/fullscreen.js"></script>
<script type="text/javascript">
var MYAPP={
CM:{},
setCodeMirror:function(obj){
this.CM=obj;
},
getCodeMirror:function(){
return this.CM;
}
}
Ext.Loader.setConfig({enabled:true, disableCaching:true});
Ext.Loader.setPath('Ext.ux','/static/ext-5.0.1/examples/ux');
Ext.require(['*']);
Ext.onReady(function(){
Ext.tip.QuickTipManager.init();
Ext.create('Ext.container.Viewport',{
layout:'border',
items:[{
region:'center',
layout:'fit',
border:false,
dockedItems:[{
xtype:'toolbar',
items:[{
xtype:'button',
icon:'/static/app/img/save.png',
tooltip:'Сохранить',
handler:function(){
// This tabpanel is corrupted when you hit Enter
}
}]
}]
}]
});
});
</script>
</head>
<body>
<br/><br/>
<textarea id="code" name="code">...Write here a lot of text, so that the last line will be beyond visible arear of the screen... Then scroll down, put cursor to the last line and hit Enter. You will see that the tabpanel with a button is corrupted</textarea>
<script type="text/javascript">
MYAPP.setCodeMirror(CodeMirror.fromTextArea(document.getElementById("code"),{
lineNumbers:true,
mode:{name:'javascript',globalVars:true}
}));
</script>
</body>
</html>
爲什麼使用html textarea,而不是使用ExtJS文本區域,http://try.sencha.com/extjs/4.1.0/docs/Ext.form.field.TextArea.1/ – Bala 2014-11-03 05:32:52
@ Bala 。謝謝!我會查一下。 – Jacobian 2014-11-03 07:14:26