我在项目可嵌套列表扩展中使用。如何使用此列表中的jquery,键和值来阅读?
List的代码如下所示:
<div class="dd" id="list1">
<ol class="dd-list">
<li class="dd-item" data-id="1">Item 1</li>
<li class="dd-item" data-id="2">Item 2</li>
<li class="dd-item" data-id="3">Item 3</li>
<li class="dd-item" data-id="4">Item 4</li>
<li class="dd-item" data-id="5">Item 5</li>
</ol>
</div>
序列化输出如下所示:
[{ “ID”:1},{ “ID”:2},{ “ID”:3},{ “ID”:4},{ “ID”:5}]
此输出由此javascript代码生成:
<script type="text/javascript">
$('.dd').nestable();
//Watch for list changes and show serialized output
function update_out(selector, sel2){
var out = $(selector).nestable('serialize');
$(sel2).html(window.JSON.stringify(out));
}
update_out('#list1',"#out1");
$('#list1').on('change', function() {
update_out('#list1',"#out1");
});
</script>
答案 0 :(得分:0)
请参阅答案here:
var test = [{"id":1},{"id":2},{"id":3},{"id":4},{"id":5}]
var result = test.filter(function( obj) {
return obj.id == 1;
});