【发布时间】:2010-01-18 09:34:50
【问题描述】:
我有一个如下的 JavaScript 数组,我需要对其进行过滤以从下面的测试数据中获取正确的子值。
var arrChildOptions2 = [
{Parent:'opt1',Value:'opt1',Text:'Parent1 - Child 1'},
{Parent:'opt2',Value:'opt1',Text:'Parent 2 - Child 1'},
{Parent:'opt2',Value:'opt2',Text:'Parent 2 - Child 2'}
];
这些值用于根据父下拉列表的更改事件填充下拉列表,如下所示。
$(function() {
$('#ddl1').change(function() {
$('#ddl2 option:gt(0)').remove();
$('#ddl2').addItems('#ddl2', arrChildOptions2[Parent=opt2]);
});
});
其中 additems 是一个遍历数组的函数。问题是我不能让它按父母过滤,我试过使用 contains 和上面的 arrChildOptions2[Parent=opt2] 但我不能让它过滤器,我更愿意找到一个简洁的解决方案而不是使用 for 循环?任何想法,干杯
【问题讨论】:
标签: javascript jquery