How do I insert a DOM element into an ordered list (in Dojo)?

I am trying to make an AJAXy view and put a partial result in my list in the right place. I can think of several options, but none are terribly good:

Option 1: return JSON, render to Javascript. This seems like the wrong place to render this, especially since the list itself is showing up on my app server. The advantage is to make sort ( response.full_name

) easier to access .

Option 2: Return HTML snippet, parse sort value. Parsing HTML into Javascript is probably worse than rendering it.

Option 3: Return the HTML snippet that also contains the section <script>

that gets graded. This can add a DOM node to the main list and then make a JS call to insert at the desired point. The downside here is that IE doesn't evaluate tags <script>

when called innerHTML

or appendChild

.

+1


source to share


1 answer


Personally, I would do # 1. There is nothing wrong with combining server-side generated HTML with client-side generated HTML, but if it is a complex procedure, it is better to keep it in one place (on the server in your case). This way you can return (as JSON) two values: the sort value and the HTML fragment.



After that, it's simple: find the position, instantiate the fragment (for example using dojo.html.set () ), and place it with dojo.place () . Or create an instance directly in place.

+2


source







All Articles