问题
I like to generate markup and at the same time adding data to nodes in the markup with jQuerys data method Store arbitrary data associated with the matched elements. Is there some way to do that with Mustache or some workaround?
See this jsFiddle for code reference: http://jsfiddle.net/fiddlebjoern/edyYu/
回答1:
you could use nested templates as suggested here.
Your list item being the second template. Now each time you want to append data run it by your second template and call jquerys append method.
Does that sound good? Is that what you wanted? Your question was somewaht unclear
回答2:
Check out this working example of Mustache with jQuery:
http://blog.xoundboy.com/?p=535
来源:https://stackoverflow.com/questions/6977727/mustache-js-how-to-hook-up-data