使用jQuery使用选择框选项值过滤JSON [英] Filter json with select box option value using jquery

查看:77
本文介绍了使用jQuery使用选择框选项值过滤JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据年份过滤制造"值.例如:当我选择年份"作为"2012"时,相关数据即;下拉框中仅应显示"def".另一个问题是,当我选择下一个值时,表中的上一个数据再次显示.请参阅该演示以获得更好的理解.

我尝试过了.

$ .each(g_Vehicle,function(index){
var sMake = g_Vehicle [index] .Make;
if($(''#DropDown_Year'').val())==''2011''){/*出于测试目的,我将年份指定为2011 */
if($ .inArray(sMake,g_MakesArray)== -1){
g_MakesArray.push(sMake);
}
}
});
http://jsfiddle.net/NFXzn/4/ [

How can i filter the "Make" values according to the year. For eg: When i select "Year" as "2012" the related data i.e; only "def" should be displayed in the drop down box. Another problem is the previous data in the table was shown again when i select next values. See the demo for better understanding.

I tried this.

$.each(g_Vehicle, function(index) {
var sMake = g_Vehicle[index].Make;
if($(''#DropDown_Year'').val())==''2011''){ /* for testing purpose i give year as 2011*/
if ($.inArray(sMake, g_MakesArray) == -1) {
g_MakesArray.push(sMake);
}
}
});
http://jsfiddle.net/NFXzn/4/[^]

推荐答案

.each(g_Vehicle,function(index){
var sMake = g_Vehicle [index] .Make;
if(
.each(g_Vehicle, function(index) {
var sMake = g_Vehicle[index].Make;
if(


(''#DropDown_Year'').val())==''2011''){/*出于测试目的,我将年份设置为2011 */
if(
(''#DropDown_Year'').val())==''2011''){ /* for testing purpose i give year as 2011*/
if (


.inArray(sMake,g_MakesArray)== -1){
g_MakesArray.push(sMake);
}
}
});
http://jsfiddle.net/NFXzn/4/ [
.inArray(sMake, g_MakesArray) == -1) {
g_MakesArray.push(sMake);
}
}
});
http://jsfiddle.net/NFXzn/4/[^]


这篇关于使用jQuery使用选择框选项值过滤JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆