javascript - Parsing an xml template using jQuery -
so have template-like script i'm trying parse jquery. issue have tags want replace data, fine, want loop on object properties, makes more difficult.
i want rely on external libraries little possible, i'm using jquery here. know angular here don't know yet.
the template code looks this:
<?xml version="1.0" ?> <div id="test"> <each obj="list"> <div class="listdiv"> <span><value>thing</value></span> <span><value>thing2</value></span> <span><value>thing3</value></span> <div> <each obj="morestuff"> <span>blah: <value>blah</value></span> <span>foo: <value>foo</value></span> </each> </div> </div> </each> </div>
and want pass in following json object:
{ list: [ { thing: 3, thing2: 4, thing3: 5, morestuff: [{blah:1, foo:2},{blah:4, foo:6}] }, { thing: 1, thing2: 1, thing3: 2, morestuff: [{blah:4, foo:6}] } ] }
what want come out this:
<div id="test"> <div class="listdiv"> <span>3</span> <span>4</span> <span>5</span> <div> <span>blah: 1</span> <span>foo: 2</span> <span>blah: 4</span> <span>foo: 6</span> </div> </div> <div class="listdiv"> <span>1</span> <span>1</span> <span>2</span> <div> <span>blah: 4</span> <span>foo: 6</span> </div> </div> </div>
i getting work alright regular expressions of course it's cleaner dom manipulation , it's more extensible well. thing causes trouble recursive nature of <each>
tags , fact <value>
tags have data parent.
i've tried ton of ways every time either have recursion issue (infinite recursion , can't replace things) or can't pull data correctly. there way nicely?
have tried these jquery plugins
http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-an-introduction-to-jquery-templating/
Comments
Post a Comment