我有一个这样的json数据:
var data = [
{ID:"1", Name: "a", ParentID: 0},
{ID:"2", Name: "b", ParentID: 0},
{ID:"3", Name: "c", ParentID: 0},
{ID:"4", Name: "aa", ParentID: 1},
{ID:"5", Name: "aaa", ParentID: 1},
{ID:"6", Name: "bb", ParentID: 2},
{ID:"7", Name: "cc", ParentID: 3},
{ID:"8", Name: "bbb", ParentID: 2},
{ID:"9", Name: "ccc", ParentID: 3},
{ID:"10", Name: "bbbb", ParentID: 2},
{ID:"11", Name: "cccc", ParentID: 3}
]
我想使用 Javascript Jquery 生成下拉列表。注意:数据排序基于 parentID 例如:ID = ParentID
{ID:"1", Name: "a", ParentID: 0},
{ID:"4", Name: "aa", ParentID: 1},
{ID:"5", Name: "aaa", ParentID: 1}
我期望结果是这样的:
<select>
<option value="1">a</option>
<option value="4">aa</option>
<option value="5">aaa</option>
<option value="2">b</option>
<option value="6">bb</option>
<option value="8">bbb</option>
<option value="10">bbbb</option>
<option value="3">c</option>
<option value="7">cc</option>
<option value="9">ccc</option>
<option value="11">cccc</option>
</select>
我能怎么做?
谢谢大家,