过滤json数据并在网格中显示数据 [英] Filter the json data and display data in a grid

查看:77
本文介绍了过滤json数据并在网格中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是json.即时消息显示年份并在选择框中进行.当我选择年份并使其相关数据时,应过滤并显示在网格中.例如,当我选择2010年并定义相关数据即2010年时. def,300& 5000应显示在网格中.任何人都可以帮我做到这一点,而无需使用任何jquery插件.

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",  }
];


这是我的代码:
http://jsfiddle.net/qK2A3/2/ [


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

推荐答案

尝试这一方法. :-)

此处的html代码...

try this one bro. :-)

html code here...

<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script><div>
  
<select id="mysel">
  <option value="2010">2010<option />
 <option value="2009">2009<option />
 <option value="2008">2008<option />
 <option value="2007">2007<option />
</option></option></option></option></select>
<table id="mytable">
  <tr>
    <th>Year</th>
    <th>Make</th>
    <th>Model</th>
    <th>SubModel</th>
  </tr>
<tr>
    <td><input type="text" id="year" value="year" /></td>
    <td>
    <td>
    <table><tbody><tr><td>
</td></tr></tbody></table></td></td></tr>
</table>
</div>



jQuery代码在这里..



jquery code here..

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",  }
];


(功能(){


( #mysel").change( var len = 0 ; for (len = 0 ; len< data.length len = " mode = 保持"/>
("#mysel").change(function(){ var len=0; for(len = 0; len <data.length len="" mode="hold" /> if(data[len].Year==


这篇关于过滤json数据并在网格中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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