1

I have 3 arrays which I am gathering from a table:

    allCamNames = $('#dat tr:gt(0) td:first-child').map(->
      $.trim $(this).text()
    ).get()
    allCamShareCount = $('#dat tr:gt(0) td:nth-child(6)').map(->
      $.trim $(this).text()
    ).get()
    allCamIds = $('#dat tr:gt(0) td:last-child').map(->
      $.trim $(this).text()
    ).get()

i want to create a select option menu in such a way that in options

<option value="allCamId">AllCamNames - share Count (AllCamShareCount)</option>

As these all are arrays so I want to place all the value in options in such way that when i have the whole options one option be like

<option value="345">One Cam - share Count (34)</option>

Plus i have a TR and while mapping all values in arrays I want to neglect this: tr = $(this).parents('tr') not to be included while mapping values.

all the three mapping functions run when i click on one of the tr's TD, so i want to exclude that TR of which td i have clicked.

onCameraMerge = ->
  tr = ''
  needToMergeId = ''
  cameraName = ''
  allCamNames = ''
  allCamShareCount = ''
  allCamIds = ''
  $("#dat").on 'click', '.merge-cam', ->
    $('#mergeModal').modal('show')
    tr = $(this).parents('tr')
    needToMergeId = tr.find('td:nth-child(9)').text()
    cameraName = tr.find('td:nth-child(1)').text()
    $("p > #mc").append cameraName
    console.log(needToMergeId)
    allCamNames = $('#dat tr:gt(0) td:first-child').map(->
      $.trim $(this).text()
    ).get()
    allCamShareCount = $('#dat tr:gt(0) td:nth-child(6)').map(->
      $.trim $(this).text()
    ).get()
    allCamIds = $('#dat tr:gt(0) td:last-child').map(->
      $.trim $(this).text()
    ).get()
    optionsHtml = ''
    i = 0
    while i < allCamNames.length
      optionsHtml += '<option value="' + allCamIds[i] + '">' + allCamNames[i] + ' - share Count (' + allCamShareCount[i] + ')</option>'
      i++
    $('#with-cam').html '<select>' + optionsHtml + '</select>'


<tbody><tr> <td><a href="/cameras/3158">hundegaard</a></td><td>vwc200</td><td><span style="color:red;">N</span></td><td><a href="/users/1465">Gert Laumann</a></td><td><span style="color:red;">N</span></td><td>0</td><td>2014-09-02T05:57:25.082Z</td><td class="center"><i class="fa fa-trash-o delete-cam"></i> | <i class="icon-camera merge-cam"></i></td><td style="display: none;">3158</td> </tr><tr> <td><a href="/cameras/1442">will cam</a></td><td>will_34f</td><td><span style="color:red;">N</span></td><td><a href="/users/209">will Creach</a></td><td><span style="color:red;">N</span></td><td>0</td><td>2014-03-23T14:19:01.176Z</td><td class="center"><i class="fa fa-trash-o delete-cam"></i> | <i class="icon-camera merge-cam"></i></td><td style="display: none;">1442</td> </tr></tbody>
3
  • show $(this).text() values Commented Jan 1, 2016 at 5:57
  • show complete code of your js click function for better understanding Commented Jan 1, 2016 at 6:26
  • i have updated the question with full code when i click on the td which have delete-cam #id then i want to ignore that whole tr @MuhammadAtif Commented Jan 1, 2016 at 6:54

1 Answer 1

1

Try this to create select

   var optionsHtml = "";
    for (var i = 0; i < allCamNames.length; i++) {
    optionsHtml += '<option value="' + allCamIds[i] + '">' + allCamNames[i] + ' - share Count (' + allCamShareCount[i] + ')</option>';
     }
    $("#idWhereYouWantToShowThisSelect").html("<select>"+optionsHtml+"</select>");

To skip cliked TR use this not(this) like

$('#dat tr:gt(0) td:first-child').not(this)
Sign up to request clarification or add additional context in comments.

3 Comments

where is the value which i want to neglect that TR?
where to .not(this) ? in mapping function?
allCamNames = $('#dat tr:gt(0) td:first-child').not(this).map(-> $.trim $(this).text() ).get() not worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.