|
1 |
| -jQuery Filter JSON Changelog |
| 1 | +# jQuery Filter JSON |
2 | 2 |
|
3 |
| -Version 1.0 |
4 |
| -============================================== |
5 |
| -- Initial release |
| 3 | +This jQuery plugin is a utility that allows you to filter a JSON based on properties. You can also have a property/value match and only those |
| 4 | +property values that match the passed in value will be returned. |
| 5 | + |
| 6 | +However, you can filter the JSON based on various parameters such as startWith or checkContains, matchCase and can either choose to return the |
| 7 | +matched values or the parent object of the matched values. You even have the option of avoiding duplicates if any. |
| 8 | + |
| 9 | +Below is a basic usage: |
| 10 | +````javascript |
| 11 | +$.fn.filterJson({ json object }, { |
| 12 | + property: "name", |
| 13 | + wrapper: true, |
| 14 | + value: "user one", |
| 15 | + checkContains: false, |
| 16 | + startsWith: true, |
| 17 | + matchCase: false, |
| 18 | + avoidDuplicates: true |
| 19 | + }); |
| 20 | +```` |
| 21 | +# Plugin Properties Explained |
| 22 | +Before digging into each property of the plugin lets describe our sample JSON. |
| 23 | +````javascript |
| 24 | +{ |
| 25 | + { |
| 26 | + "id": 12345, |
| 27 | + "name": "User One", |
| 28 | + |
| 29 | + },{ |
| 30 | + "id": 23456, |
| 31 | + "name": "User Two", |
| 32 | + |
| 33 | + },{ |
| 34 | + "id": 34567, |
| 35 | + "name": "User Three", |
| 36 | + |
| 37 | + } |
| 38 | + . |
| 39 | + . |
| 40 | + . |
| 41 | +} |
| 42 | +```` |
| 43 | + |
| 44 | +* property (mandatory, default is null): This options takes the value of the property that you need to filter the JSON with. For the above sample JSON we can have three properties |
| 45 | +id, name and email. |
| 46 | + |
| 47 | +* wrapper (optional, default is false): If set to true, it will return an array of the parent object of the matched property else will return an array of value itself. |
| 48 | +For instance if we are filtering the above sample JSON with 'name' property and wrapper is set to true, then an array of all the Objects which |
| 49 | +have the 'name'property will be returned. |
| 50 | +If the wrapper is set to false, then an array of only the values of the property will be returned. For the above sample JSON |
| 51 | +["User One", "User Two", "User Three"] would be returned. |
| 52 | + |
| 53 | +* value (optional, default is ""): An optional value passed to be matched with the value of the matched property value. |
| 54 | + |
| 55 | +* checkContains (optional, default is false): Setting this option to true will check if the matched property's value contains the passed in value. However, passing a value becomes mandatory for this to work. |
| 56 | +This option will be considered only if it is true and startsWith is not set to true. |
| 57 | + |
| 58 | +* startsWith (optional, default is false): Setting this option to true will check if the matched property's value starts with the passed in value. However, passing a value becomes mandatory for this to work. |
| 59 | +This options takes precedence over checkContains if it is set to true. |
| 60 | + |
| 61 | +* matchCase (optional, default is false): If set to true will perform case-sensitive search of values. |
| 62 | + |
| 63 | +* avoidDuplicates (optional, default is false): If set to true will avoid duplicate objects. |
| 64 | + |
| 65 | +# Known Issues |
| 66 | + |
| 67 | +For this plugin to work in IE7 and below, you will have to include JSON2 |
| 68 | + |
| 69 | +# Licence |
| 70 | + |
| 71 | +Copyright (c) 2012 Kapil Kashyap. |
| 72 | +Dual licensed under MIT License and GPL License. |
0 commit comments