I am trying to use jquery context menus on my grading web site. I have the following code:
$.contextMenu({
selector: 'span.context-menu',
callback: function(key, options) {
updatePerformancegradecontext(key,$(this).attr('id'));
},
items: {
"1": {name: 'Beginning'}
"2": {name: 'Developing'},
"3": {name: 'Proficient'},
"4": {name: 'Extending'},
"sep1": "---------",
"exc": {name: "Excused"},
"abs": {name: "Absent"},
"nhi": {name: "Not Handed In"},
"empty": {name: "No Grade"}
}
});
I would like the first four items on the menu to be determined at runtime. When the webpage loads, I want to read some data from the page and create an object as follows:
var p0 = new Object;
p0.name=document.getElementById('perf0').innerHTML;
How do I insert this object into one of the items? I have tried many variations such as:
items: {
"1": p0,
and
items: {
"1": {p0},
etc. What am I missing? How can I create the items object using the p0 object as the name object? Or should I scrap javascript and just write this using HTML5 context menus?
question from:
https://stackoverflow.com/questions/65952530/how-to-insert-a-variable-into-a-javascript-object-for-a-context-menu 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…