-
12 Sep 2012 4:17 PM #1
Unanswered: Ext.each returns half complete records and half "undefined"
Unanswered: Ext.each returns half complete records and half "undefined"
I have used Ext.each(array, function(curr, index){...doSomething...}); to perform an action using each element in that array but what I have noticed in some cases is that it will return half of the items complete and half "undefined". I have done some work arounds to make it ok but now I am running into and issue that I can't seem to fix and maybe someone out there has an explanation/solution.
I am using a tree that has a folder full of records that I want to iterate over and throw them into another folder or leave them where they are based on their name.
if you do a console.log on curr before the if statement and comment out the if statement then you will see half of the records complete and half "undefined".Code:folder.eachChild(function(curr){ if(Ext.Array.contains(parents, curr.get('name')){ otherFolder.appendChild(curr); } });
Extjs 4.1 using firefox 13.0.1
This is my first post so let me know if I should fix something or provide more info. Thanks
-
12 Sep 2012 4:37 PM #2
Your problem is that folder.childNodes will be shrinked each time you move one of its child node to other folder. Below is one of solution to fix this problem.
Code:var needToMove = []; folder.eachChild(function(curr){ if(Ext.Array.contains(parents, curr.get('name')){ //otherFolder.appendChild(curr); needToMove.push(curr); } }); for(var i = 0, len = needToMove.length; i < len; i++){ otherFolder.appendChild(needToMove[i]); }
-
12 Sep 2012 4:42 PM #3
AHHH! Why didn't I think of that. So obvious. Thank you for responding so quickly.


Reply With Quote