[英]How to add dynamic objects to javascript object property
I am trying to develop a wordpress plugin and for it I need to add tinymce listbox with dynamic values. 我正在尝试开发一个wordpress插件,为此,我需要添加带有动态值的tinymce列表框。 At the moment I have stored dynamic objects in listv array and I need to push them in to tinyMCE.activeEditor.settings.myKeyValueList .
目前,我已将动态对象存储在listv数组中,并且需要将它们推入tinyMCE.activeEditor.settings.myKeyValueList 。 But it wont work.
但它不会工作。 even I have tried push and valueOf javascript methods but still no luck.
即使我尝试了push和valueOf javascript方法,但还是没有运气。
function getValues() {
//Set new values to myKeyValueList
var listv = [];
var len = pw_script_vars.ad;
for (i = 0; i < len.length; i++) {
listv[i] = {
text: pw_script_vars.ad[i],
value: pw_script_vars.ad[i]
};
}
for (i = 0; i < listv.length; i++) {
tinyMCE.activeEditor.settings.myKeyValueList += [listv[i]];
}
return tinyMCE.activeEditor.settings.myKeyValueList;
}
From what I have seen by searching for tinyMCE myKeyValueList
, it seems like you have to simply assign the value 从我通过搜索
tinyMCE myKeyValueList
所看到的结果tinyMCE myKeyValueList
,似乎您只需要简单地分配值即可
tinyMCE.activeEditor.settings.myKeyValueList = listv;
instead of trying to add to it: 而不是尝试添加到它:
for (i = 0; i < listv.length; i++) {
tinyMCE.activeEditor.settings.myKeyValueList += [listv[i]];
}
If you want to append to the existing myKeyValueList
array (if it actually exists), see How to extend an existing JavaScript array with another array, without creating a new array? 如果要追加到现有的
myKeyValueList
数组(如果它确实存在),请参见如何在不创建新数组的情况下用另一个数组扩展现有的JavaScript数组? . 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.