javascript - Append table cells to select boxes in indexed order -
i having huge brain fart efficiency right now.
the idea here if have static table
(unfortunately formatted way data i've received), how appropriately append
select option dropdown
every value table categorized easily?
i have working, seems if make more efficient current statement. have feeling dom
manipulation have going on, if tried use on table thousands of items lag browser. let's code.
js fiddle: http://jsfiddle.net/z2v2p/1/
html:
<table id='data'> <tr> <td>item 1</td> <td>value 1</td> <td>prop 1</td> </tr> <tr > <td>item 2</td> <td>value 2</td> <td>prop 2</td> </tr> <tr > <td>item 3</td> <td>value 3</td> <td>prop 3</td> </tr> </table> <select id="item"></select> <select id="value"></select> <select id="prop"></select>
javascript/jquery:
$('tr td').each(function() { var $this = $(this); var text = $this.text(); var select = '<option value="'+text+'">'+text+'</option>'; switch($this.index()){ case 0: $('#item').append(select); break; case 1: $('#value').append(select); break; case 2: $('#prop').append(select); break; default: alert('unexpected error.'); } });
so, suppose questions are:
- is there easy way make more efficient?
- perhaps utilizing
array
cache values, ,append
them that? - or there easier method of using
index
of items instead ofswitch case
render quicker , more expandable furthertd
s if implemented?
i appreciate of help.
i've considered converting darn table json
object, figured i'd reach out here first.
Comments
Post a Comment