Ext js 5 SyntaxError: unterminated string literal issue
-
21-12-2019 - |
Question
I test below code of Extjs5:
Ext.create('Ext.window.Window', {
title: 'try extjs text area',
width: 900,
height: 500,
layout: 'fit',
items: [{
xtype: 'textarea',
value: ' The first line \n The second line',
border: true,
autoScroll: true,
draggable: true
}]
}
).show();
The issue is text content contain \n as below : value: ' The first line \n The second line',
and it will get error: SyntaxError: unterminated string literal
But I need to display a new line in textarea . What's correct solutions for this ?
BTW , This issue is caused by Tree Panel render :
I have a render method like below in MainController.js :
renderLogs: function (logs, p, record) {
return logs? '<div><img src="default-more.png" /
onclick="Ext.create(\'Ext.window.Window\', /
{ title: \'try extjs text area\', /
width: 900,height: 500, /
layout: \'fit\', /
items: [{xtype: \'textarea\', /
value: \'"+logs+"\', /
border: true,autoScroll: true,draggable: true}]}).show(); "> /
</img></div>' : '';
}
So if logs content \n , it will get ERROR - SyntaxError: unterminated string literal
Solution
Inside 'items' parameter: text is not correct 'sub-parameter' of 'textarea', 'value' is the correct. That was the problem. Correct code is:
Ext.create('Ext.window.Window', {
title: 'try extjs text area',
width: 900,
height: 500,
layout: 'fit',
items: {
xtype: 'textarea',
value: ' The first line \n The second line',
border: true,
autoScroll: true,
draggable: true
}}
).show();