OriganalArray=[
{member_Key: 1},
{member_Key: 2},
{member_Key: 3},
{member_Key: 4},
{member_Key: 5},
{member_Key: 6},
{member_Key: 7},
{member_Key: 8},
{member_Key: 9},
]
我使用复选框
将OriganalArray绑定在一个表格中 FilterArray=[
{member_Key: 1},
{member_Key: 2},
{member_Key: 3},
]
现在,当我点击按钮
时,复选框必须根据FilterArray自动选择答案 0 :(得分:0)
使用jQuery,您可以使用.slice()
执行此类操作,对于演示,我使用了无线电:
var OriganalArray=[
{member_Key: 1},
{member_Key: 2},
{member_Key: 3},
{member_Key: 4},
{member_Key: 5},
{member_Key: 6},
{member_Key: 7},
{member_Key: 8},
{member_Key: 9}
]
$('button').click(function(){
var filtered = OriganalArray.slice(0, +$(':radio:checked').val());
$('p').html('<pre>'+JSON.stringify(filtered)+'</pre>');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label>3 <input name='filter' type='radio' value='3'></label>
<label>4 <input name='filter' type='radio' value='4'></label>
<button>Filter</button>
<p></p>