自动排序方法以附加功能 [英] auto sort method to append function
问题描述
我有一个动态列表,用户可以向ul添加li(项目).他们可以选择1,2和3级.目前,它们都附加到ul,没有排序功能.我希望级别1始终在插入时位于第一个,级别2随之出现,然后是级别3,将其视为优先级.例如,我在一个级别为2的列表中有4个项目,那么当一个级别为1的新项目进来时,它不会追加到最后一个项目上,而是追加到第一个项目上.
I've dynamical list that user can add li (items) to a ul. They can choose level 1,2 and 3.. for now they all append to ul, with no sorting function. I want the level 1 always on the 1st when been inserted, level 2 will come along and then followed by level 3, think of it like priority. for example I've 4 item in a list with level 2, then when a new item with level 1 come in, it doesn't append on the last item, but the 1st.
我想知道我是否必须自己编写排序函数,thx
I'm wondering must I write the sort function on my own, thx
推荐答案
执行此操作的方法是将属性附加到特定级别的li元素上,例如:
A method to do this will be attach attribute to li elements at specific level like:
<ul>
<li class="level1">this is level 1</li>
<li class="level1">this is level 1</li>
<li class="level1">this is level 1</li>
<li class="level2">this is level 2</li>
<li class="level2">this is level 2</li>
<li class="level3">this is level 3</li>
<li class="level3">this is level 3</li>
</ul>
然后在适当的级别插入
检查演示: http://jsfiddle.net/Hms7Y/
这篇关于自动排序方法以附加功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!