The following code outputs a comma separated array for the var cats. The array has six items as the list "banner" has two columns and three rows of items. I can access the array items in the first row by entering cats[0][0] and cats[0][1].
However, when I attempt to access the array items in rows 2 or 3 by doing cats[1][0],cats[1][1],cats[2][0] or cats[2][1] the array comes up empty.
Can someone help me understand why please?
<script src="/Utilities/jquery.min.js"></script>
<p style="font-size:20px;" width="500px;" id="Ptask"></p>
<script>
SP.SOD.executeOrDelayUntilScriptLoaded(retrivetasklistitems, 'SP.js');
var colltaskListItem;
var listItemArray = [];
var cats = [];
var tasks;
function retrivetasklistitems() {
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('banner');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(
'<View><Query><Where><IsNotNull><FieldRef Name="Url"/></IsNotNull></Where></Query></View>'
);
this.colltaskListItem = oList.getItems(camlQuery);
clientContext.load(colltaskListItem);
/* execute the query to get the loaded items */
clientContext.executeQueryAsync(
/* onSuccess Function */
Function.createDelegate(this, this.OnQuerySucceeded),
/* onFail Function */
Function.createDelegate(this, this.onQueryFailed)
);
}
function OnQuerySucceeded(sender, args) {
var count = 0; // for directory list
var listItemEnumerator = colltaskListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
var title = oListItem.get_item('Title');
var url = oListItem.get_item('Url');
var categories = [title, url];
listItemArray[count] = new Array(2);
for (var i = 0; i<listItemArray[count].length; i++) {
if(categories[i] == null || categories[i] == undefined) {
listItemArray[count][i] = " ";
} else {
listItemArray[count][i] = categories[i];
}
}
count++;
var cats = listItemArray;
tasks = "<p>" + cats[1][1] + "</p>" + "<br />";
}
$("#Ptask").html(tasks);
}
function OnQueryFailed(sender, args) {
alert('Error: ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>