Search code examples
javascriptjqueryjquery-eventsjson2html

json2html eventData example


It is my understanding from json2html Usage -> jQuery that events can be hooked up inside json2html(), but there doesn't seem to be an example in Examples -> jquery.

Please show a json2html eventData example.


Solution

  • not too sure if I understand your question exactly .. are you looking for examples on how to use events with jquery.json2html? or how to pass an object to keep context using eventData?

    In either case here's a simple example that does both:

    var data = [{'name':'click me'}];
    
    var transform = {'tag':'button','html':'${name}','onclick':function(e){console.log(e.data);}};
    
    $('#buttons').json2html(data,transform,{'eventData':'some data object'});