Can anyone help with this (Javascript arrays)?

684 views Asked by At

Hi I am new to Netui and Javascript so go easy on me please. I have a form that is populated with container.item data retuned from a database. I am adding a checkbox beside each repeater item returned and I want to add the container item data to an array when one of the checkboxes is checked for future processing.

The old code used Anchor tag to capture the data but that does not work for me.

<!--netui:parameter name="lineupNo" value="{container.item.lineupIdent.lineupNo}" />

here is my checkbox that is a repeater.

<netui:checkBox dataSource="{pageFlow.checkIsSelected}" onClick="checkBoxClicked()" tagId="pceChecked"/>

this is my Javascript function so far but I want to a way to store the container.item.lineupIdent.lineupNo in the array.

function checkBoxClicked()
{
var checkedPce = [];
var elem = document.getElementById("PceList").elements;

for (var i = 0; i < elem.length; i ++)
{
if (elem[i].name == netui_names.pceChecked)
{
if (elem[i].checked == true)
{
//do some code. }
}
}
}

I hope this is enough info for someone to help me. I have searched the web but could not find any examples.

Thanks.

2

There are 2 answers

1
Tom On
var checkedPce = new Array();

//some other code

checkedPce[0] = stuff_you_want_to_add
2
John Fisher On

If you merely want to add a value to an array, you can use this code:

var array = [];
array[array.length] = /* your value */;

You may need to use a dictionary approach instead:

var dictionary = {};

function yourCode(element) {
  var item = dictionary[element.id];
  if (item == null) { 
    item = /* create the object */;
    dictionary[element.id] = item;
  }

  // Use the item.
}