I would like to instantiate a new object with dynamic parameters coming from an exernal String.
Here is the code:
const editorInstance = new Editor('#edit',
{
placeholderText: null,
theme: 'dark',
language: 'en',
linkList:[{text: 'test',href: 'test',target: '_blank'}],
events: {
initialized: function () {
const editor = this
this.el.closest('form').addEventListener('submit', function (e) {
jQuery('#gs_editor_content').hide();
jQuery(this).append('<div class="loadingDiv"> </div>');
o.script
});
texta = jQuery('#myeditor').find('textarea');
targetFile = texta.attr('rel');
content = editor.$oel.val();
e.preventDefault();
var fd = new FormData();
fd.append( 'name' ,targetFile);
fd.append( 'html', editor.$oel.val() );
$.ajax({
url : 'http://localhost/Update',
type : 'POST',
data: fd,
processData : false,
contentType : false,
async : false,
success : function(data, textStatus, request) {}
});
jQuery('#myeditor').dialog("close");
}
}
}
})
I would need to modify the parameters linkList
before instantiating my object as I receive a new list received from my server.
I tried to use eval or parseFunction but I encounter an unexpected identifier error.
any idea how I can achieve this ?
EDIT
I really need to update the parameter before creating the Object, which is not the same thing as mentioned in the question suggested as duplicate. By the way I also need to create my object after updating the parameter...
EDIT 2
I also tried to simply include my var containing the String but it doesn't work:
var dropdownFiles = "[{text: 'test',href: 'test',target: '_blank'}]";
const editorInstance = new Editor('#edit',
{
placeholderText: null,
theme: 'dark',
language: 'en',
linkList:dropdownFiles,
events: {
.....
from Javascript Instanciate new Object with dynamic parameter from String
No comments:
Post a Comment