javascript - Copying the js objects value into the html as string -


i want create html elements using values of javascript objects not global.

if run following code, take error: "params not defined". want copying value argument in html code.

if (params.data.allowedoperations.indexof('put') != -1) {    return "<a onclick=\"ahey('put',params.data.allowedoperations)\" href=\"#\"> put </a>"; } 

you use:

if (params.data.allowedoperations.indexof('put') != -1) {     return "<a onclick=\"ahey('put','"+params.data.allowedoperations+"')\" href=\"#\"> put </a>"; } 

alternatively create anchor node , add eventlistener or store operations in different attribute e.g.:

if (params.data.allowedoperations.indexof('put') != -1) {     return "<a onclick=\"ahey('put', this.dataset.allowedoperations)\" data-allowed-operations=\""+params.data.allowedoperations+"\" href=\"#\"> put </a>"; } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -

Why does a .NET 4.0 program produce a system.unauthorizedAccess error on a Windows Server 2012 machine with .NET 4.5 installed? -