Creating your own custom jquery template engine?

I had a quick search on stackoverflow .. but I could not find anything that came after.

I am trying to understand / get some guidance on how to create my own simple template engine for jQuery.

I basically have a standard AJAX call to get some XML (yes .. old-fashioned I know .. and I will need to drag this into the JSON world, maybe). So I end up saying something like the following (just a clipped idea):

<rows>
    <myFieldname1>some data</myFieldname1>
    <myFieldname2>some data too</myFieldname2>
    .. and so on ...
</rows>

So, for SINGLE based entries, I have something that I call "PageDataMagic" (yes, very dramatic) which, using jQuery, iterates through XML and maps the xml node values ​​to HTML elements (there is a bit checking if the element is a checkbox, etc.) - this is done by XML nodes, which are called field names from the / database, while the element identifier is named this way, it works.

Ok, to the point. If I want to have some kind of "template", that is, preferably external JS / HTML, how would I dynamically match field names and dynamically add a repeating template? I think there is an append () function in jQuery? I just think, trying to read the template file and create line instances from this.

Does that make sense? Maybe you need more coffee ...

Any help though much appreciated ...

David.

--- EDIT ---

, XML - . , JSON, , . XML, - ..

+3
2

, XSLT? , .

+1

jQuery , .

+2

Source: https://habr.com/ru/post/1780537/


All Articles