PDA

View Full Version : Each, forEach, on array not a function



insomnix
6 May 2013, 4:43 PM
I don't know why this is so hard. I have spent over an hour trying to duplicate something that took me five minutes in jquery.
I have an associative array with several values. I'm trying to place these values into a list to display in a window. Below is the code that works in jquery:

var listArray = {};
...
$.each(listArray, function(key, val) {
val += key + ' ' + val + '\n';
});
But when I converted this project into a extjs project I needed to change how a few things worked and this function no longer works the way it was written. I tried several different ways and now I'm to the point I'm ready to throw my computer out the window. Below is my last iteration of this function. Can someone tell me what I am doing wrong here, because this is just a stupid problem to get hung up on.

var listArray = {};
...
listArray.forEach(function(element, index, array){
val += index + ' ' + element + '\n';
});

evant
6 May 2013, 5:05 PM
Ext uses a similar approach to jQuery, we don't augment the native prototype, so you need to call an Ext method.

To iterate over an object literal: http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.Object-method-each
To iterate over an array: http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.Array-method-each

It's probably worth noting that typically you wouldn't call an object literal an "array" in javascript.

Kikketer
6 Nov 2013, 2:37 PM
I realize I'm digging up an old question, but the "each" function is giving me some trouble with accessing a "Ext.Object.classify.objectClass":

Ext.Object.classify.objectClass {SearchNavView: "searchnavview", SearchController: "RisktracMobile.controller.SearchController", MasterNavView: "masternavview"}

I'm getting this from a
this.getRefs() call, and I would like to simply iterate over them.



Ext.Object.each(this.getRefs(), function() { alert("BAM") })

Does nothing, the Ext.Object.getSize(this.getRefs()) returns 0

How do I use Sencha's object in Sencha's Object iterator?