Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter the json data and display data in a grid

Here is the json. Im displaying year and make in a select box. When i select an year and make its related data should filter and display in a grid.For eg when i select 2010 and def the related data i.e,2010. def, 300 & 5000 should be displayed in the grid. Can any one help me to do this with out using any jquery plugins.

var data = [
    { Year: "2011", Make: "abc", Model: "100", SubModel: "5000", },
    { Year: "2011", Make: "abc", Model: "200", SubModel: "6000",  },
    { Year: "2010", Make: "def", Model: "300", SubModel: "5000",  },
    { Year: "2011", Make: "def", Model: "100", SubModel: "1000",  }
];

Here is my code: http://jsfiddle.net/qK2A3/2/

like image 327
Anshu Avatar asked Nov 12 '22 18:11

Anshu


1 Answers

Ans to my ques

function getRelated() {
        $.each(g_Vehicle, function (index) {
            var sMake = g_Vehicle[index].Make;
            if (g_Vehicle[index].Make == $('#DropDown_Make').val() && g_Vehicle[index].Year == $('#DropDown_Year').val()) {
                $(".ModelClass").html(g_Vehicle[index].Model);
                $(".SubModelClass").html(g_Vehicle[index].SubModel);
            }
        });
    };

DEMO: http://jsfiddle.net/ybT7a/ It's working.

like image 111
Anshu Avatar answered Nov 15 '22 09:11

Anshu