javascript - Strategy to sort html content for writing -


I have found a general question about a strategy to sort the HTML elements. Here's a prerequisite:

I'm dynamically creating content that will be written in an HTML file. This content is written on a string that will be saved in the body of an HTML file later. There is a hierarchical representation of UL and Li tags in the content, for example (coded with spaces and on separate lines for clarity)

  var mText = " ul> ; "; MText + = "& lt; li class = 'folder' & gt; Folder 1"; Mteext + = "& lt; ul & gt;"; Mteext + = "& lt; li class = 'page' & gt; page 3 & lt; / li & gt;"; MText + = "& lt; li class = 'page' & gt; page2 "; Mteext + = "& lt; li class = 'folder' & gt; sub folder 2"; Mteext + = "& lt; ul & gt;"; Mteext + = "& lt; li class = 'page'> sub page 3 "; MText + = "& lt; li class = 'page' & gt; sub page 1 & lt; / li & gt;"; Mteext + = "& lt; / ul & gt;"; MText + = "& lt; / li>"; Mteext + = "& lt; li class = 'folder' & gt; sub folder 1"; Mteext + = "& lt; ul & gt;"; Mteext + = "& lt; li class = 'page' & gt; sub page 5 & lt; / li & gt;"; Mteext + = "& lt; li class = 'page' & gt; sub page 4 & lt; / li & gt;"; Mteext + = "& lt; / ul & gt;"; MText + = "& lt; / li>"; Mteext + = "& lt; / ul & gt;"; MText + = "& lt; / li>"; Mteext + = "& lt; / ul & gt;";   

So I end up with string presentations of those elements that I want to write (consider that pseudo-code if you get typo or other discrepancies) in the hierarchy level Could.

Now, I have to decide that the name or file name of the folder or both are made from the hierarchy of this string objects (a linked list) so that by changing the text to that structure First sorting presents the same issues ... and I am trying to figure out whether sorting before conversion will be easy or not after the string or after

How do I do about doing this? Convert to a multi-dimensional array, sort array and then convert back to string presentation? Or is there some way I can sort the content of the string?

I'm not a newbie for javascript, and I think sorting - this is not a problem - but I'm just looking for normal directions, and thanks for your thoughts!

I will go with string sorting of arrays before string conversion. The performance will be much better because sorting an array of objects is very light by changing the content of the string (especially a very large string).

In addition, when you are combining a large amount of string operations, you should use the array method:

  var mText = new Array (); MText.push ("& lt; li class = 'folder' & gt; Folder 1"); MText.push ("& lt; ul & gt;"); MText.push ("& lt; li class = 'page' & gt; page 3 & lt; / li & gt;"); MText.push ("& lt; li class = 'page' & gt; page2 ;); MText.push ("& lt; li class = 'folder' & gt; sub folder 2); MText.push ("& lt; ul & gt;"); MText.push ("& lt; li class = 'page' & gt; sub page 3 ;); MText.push ("& lt; li class = 'page' & gt; sub page 1 ;); MText.push ("& lt; / ul>"); MText.push ("& lt; / li>";); MText.push ("& lt; li class = 'folder' & gt; sub-folder1"); MText.push ("& lt; ul & gt;"); MText Push ("& lt; li class = 'page' & gt; sub page 5 ;); MText.push ("& lt; li class = 'page' & gt; sub page 4 & lt; / li & gt;"); MText ("& lt; / ul & gt;"); MText.push ("& lt; / li>"); MText.push ("& lt; / ul>"); MText.push ("& lt; / li>"); MText.push ("& lt; / ul>"); // This will make the final string return mText.join ("");   

This "+ =" method in most cases.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

c# - Confused over DLL entry points (entry point not found exception) -