jQuery / Javascript boolean -


i have piece of code working user can choose download "slice" of pie chart or whole thing.

when click on slice, send variable called source tells me slice came from.

right working on "download all" button. source all.

this loop looks if user selects slice:

// loop on our data $.each(seed.dataset,function(key, value){    if(this[col] == slice){       table += '<tr>';       table += '<td>'+this.escalationid+'</td>';       table += '<td>'+this.escreasonid+'</td>';       table += '<td>'+this.reasontext+'</td>';       table += '<td>'+this.esccreatedby+'</td>';       table += '<td>'+this.esccreatorfirst+'</td>';       table += '<td>'+this.esccreatorlast+'</td>';       table += '</tr>';   } }); 

the if statement within loop controls data including in table variable. question is, how can choose when want enforce if statement or ignore (allowing data added table var)?

the obvious wrapping in if statement feel there might cleaner way without having duplicate of table data.

end result bool saying if source=all include rows else if source=slice enforce if statement include data looking for.

update

essentially looking more clean way this:

// loop on our data     $.each(seed.dataset,function(key, value){        if(source == 'slice'){          if(this[col] == slice){            table += '<tr>';            table += '<td>'+this.escalationid+'</td>';            table += '<td>'+this.escreasonid+'</td>';            table += '<td>'+this.reasontext+'</td>';            table += '<td>'+this.esccreatedby+'</td>';            table += '<td>'+this.esccreatorfirst+'</td>';            table += '<td>'+this.esccreatorlast+'</td>';            table += '</tr>';        }        // downloading ignore constraint        }else{            table += '<tr>';            table += '<td>'+this.escalationid+'</td>';            table += '<td>'+this.escreasonid+'</td>';            table += '<td>'+this.reasontext+'</td>';            table += '<td>'+this.esccreatedby+'</td>';            table += '<td>'+this.esccreatorfirst+'</td>';            table += '<td>'+this.esccreatorlast+'</td>';            table += '</tr>';       }     }); 

you can use boolean ignoreall "or" condition existing if condition shown below

// loop on our data var ignoreall = true; // change value per requirement $.each(seed.dataset,function(key, value){    if(ignoreall || this[col] == slice){       table += '<tr>';       table += '<td>'+this.escalationid+'</td>';       table += '<td>'+this.escreasonid+'</td>';       table += '<td>'+this.reasontext+'</td>';       table += '<td>'+this.esccreatedby+'</td>';       table += '<td>'+this.esccreatorfirst+'</td>';       table += '<td>'+this.esccreatorlast+'</td>';       table += '</tr>';   } }); 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -