1

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

1

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'});
Chad Brown
  • 1,627
  • 1
  • 13
  • 22
  • 1
    no it won't .. short hand can only be used within direct attributes of the html element. Instead within a function you can access the object directly using e.obj eg. "onclick":function(e){ console.log(e.obj);} – Chad Brown Jun 03 '14 at 19:32