jquery - How can I skip objects from a JSON file if the value of a key = 0? -
jquery - How can I skip objects from a JSON file if the value of a key = 0? -
i have table beingness populated json file, working far i'm trying skip objects have value of 0 key named "member_count". possible?
this code:
$mygroupstable = $('#my_groups_table'); $.ajax({ url: 'http://testingsite.com/jsondata/mygroups.json', datatype:'json', success:function(data){ $.each(data.groups, function(key, val){ $mygroupstable.append('<tr><td><input type="checkbox" class="groupselector" member_count="' + val.member_count + '" value="' + val.value + '" id="' + val.id + '" name="' + val.name + '" group_name="' + val.group_name + '" /></td><td style="width:10px;"></td><td><label for="' + val.id + '">' + val.group_name + '</label></td></tr>'); }) }, });
the json file looks this:
{ "groups": [ { "id": "data1", "member_count": "1", "value": "255", "name": "data[]", "group_name": "group 1" }, { "id": "data2", "member_count": "5", "value": "256", "name": "data[]", "group_name": "group 2" }, { "id": "data3", "member_count": "4", "value": "257", "name": "data[]", "group_name": "group 3" }, { "id": "data4", "member_count": "6", "value": "258", "name": "data[]", "group_name": "group 4" }, { "id": "data5", "member_count": "0", "value": "259", "name": "data[]", "group_name": "group 5" } ]}
in scenario grouping 5 should not appended table. help much appreciated!!
try this:
var $mygroupstable = $('#my_groups_table'); var url = 'http://testingsite.com/jsondata/mygroups.json.json'; $.getjson(url, function(data) { $.each(data.groups, function(key, val) { if (val.member_count !== "0") { $mygroupstable.append('<tr><td><input type="checkbox" class="groupselector" member_count="' + val.member_count + '" value="' + val.value + '" id="' + val.id + '" name="' + val.name + '" group_name="' + val.group_name + '" /></td><td style="width:10px;"></td><td><label for="' + val.id + '">' + val.group_name + '</label></td></tr>'); } }); });
jquery
Comments
Post a Comment