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 -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

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