javascript - How to remove a null object from json -


I'm new to bootstrap js. I have a table with Bootsrap JS, whose data came from the JS file. Here's the code -

  & lt; Div class = "container-fluid" & gt; & Lt; Div class = "row" & gt; & Lt; Div class = "col-md-8" & gt; & Lt; Div class = "fixedscroll" & gt; & Lt; Table id = "user_table" class = "table-table-hover table-border table-striped responsive" style = "margin-down: 0;" Class = "display" & gt; & Lt; Thead & gt; & Lt; TR & gt; & Lt; Th & gt; UID & lt; / Th & gt; & Lt; Th & gt; Name & lt; / Th & gt; & Lt; Th & gt; Address & lt; / Th & gt; & Lt; Th & gt; Tag & lt; / Th & gt; & Lt; Th & gt; Edit tag & lt; / Th & gt; & Lt; / TR & gt; & Lt; / Thead & gt; & Lt; / Table & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; Function showAll () {$ .ajax ({url: "showAll", datatype: "Jason", success: function (data) {$ ('# user_table tr: gt (0)'). Remove (); jQuery.each (Data ['payload'], function (index, value) {var row = '<">' + '& lt; td id =" tduid "& gt;' + value ['uid'] + '& Lt; td & gt;' + value ['name'] + '& lt; / td>' + '' + value ['Address'] + '& lt; / td & gt;' + '& lt; Td & gt;' + value ['tag1'] + ',' + value ['tag2'] + ',' + value ['Tag3'] + '& lt; / td & gt;' + '& lt; td & gt;' + '& lt Adend (line); Button (class = "deleteUser btn btn-danger" type = "submit "& Gt; Edit & lt; / button & gt; '+' & lt; / td & gt; & lt; / tr & gt; '$' ('# user_table';));}}); < / Code> 

Now this Pello My JS is the name, which came from a servlet, where I call the database.

Now, there are 3 tags. But some lines have 2 tags, when I put values ​​in JS - Looks like Jason -

  {"payload": [["uid": "u01", "name": "allah", "address": "damdm", "tag1 ":" Aircel "," tag2 ":" Vodafone "," tag3 ":" airtel "}, {" uid ":" u02 "," name ":" win "," address ":" baruipur "," tag1 "", "Tag2": "" tag3 ":" aircel "}, {" uid ":" U03 "," name ":" diba "," address ":" jadavpur "," tag1 ": "Vodafone", "tag2": "aircel", "tag3": "Airtel", "tag2": "Vodafone", "tag3": "Airtel"}, "UID": "u04", "Name": "Tommy", "Address": "Baguihati", "tag1": "Aircel" "Vodafone", "tag3": "Airtel", "", "" "," name ":" junkie "," address ":" Rahara "," tag1 ":" "" tag2 " "," "Name": "pride", "address": "tripura", "tag1": "aircel", "tag2": "vodafone", "tag 3": "Airtel"}}}  

Now you can see, for UID = U2 there are 2 tags and the output looks like a picture. How can I remove empty values ​​or empty values ​​??? Please help me anybody ... Enter image details here

I think, you are saying about the , in the additional columns ... there is a mess solution.

  $ AJAX ({url: "showAll", datatype: "Jason", success: function (data) {$ ('# user_table tr: gt (0)'). Remove (); jQuery.each (data ['payload'] , Function (index, value) {var tag = $ .map ([value.tag1, value.tag2, value.tag3], function (value) {return value || undefined;}); var line = '& lt; Tr & gt; '+' & lt; td id = "tduid" & gt; '+ value [' uid '] +' & lt; / td & gt; '+'  '+ Value ['Name'] + '& lt; / td>' + '' + value ['address'] +' & lt; / td> '+' & lt; td & Gt; '+ Tag +' & lt; / td> '+' & lt; Td & gt; '+' & lt; button class = "deleteUser btn btn-danger" type = "submit" & gt; Edit & lt; / button & gt; '+' & lt; / td & gt; & lt; / tr & gt; '$ (' # user_table ') (Line).});}}); As <@  

@nlnitak said

  var tag = [value.tag1, value.tag2, value.tag3] .filter (function ( Value) {return value! == undefined;}); Console.log (tag)  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -