Ext JS 5 SyntaxError: problema letterali di stringa nonterminata
-
21-12-2019 - |
Domanda
Prova sotto il codice di 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();
.
Il problema è il contenuto di testo contiene \ N come di seguito: Valore: 'La prima riga \nla seconda riga',
E riceverà un errore: SyntaxError: Stringa nonterminata Letterale
Ma ho bisogno di visualizzare una nuova linea in Textarea.Quali sono le soluzioni corrette per questo?
btw, questo problema è causato da un pannello albero rendering:
Ho un metodo di rendering come di seguito 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>' : '';
}
.
Quindi se registri il contenuto \n, riceverà errori - SyntaxError: String Letterale nonterminata
Soluzione
All'interno del parametro 'elementi': il testo non è corretto 'sub-parametro' di 'TextArea', 'Value' è il corretto.Questo era il problema.Il codice corretto è:
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();