This address: http://blog.csdn.net/sushengmiyan/article/details/39009555
Sencha official Api:http://docs.sencha.com/extjs/5.0/apidocs/#!/api/ext-method-each
This article Sushengmiyan
--------------------------------------------------------------------------------------------------------------- ---------------------
Take a look at the official introduction:
Iterates an array or a iterable value and invoke the given callback function for each item.
Iterate through all the arrays that can be looped, or iterate over variables, and execute a given callback function to handle each member.
Here's an example of a simple array:
var countries = [' Vietnam ', ' Singapore ', ' states ', ' Russia ']; Ext.Array.each (countries, function (name, index, countriesitself) { console.log (name);}); var sum = function () { var sum = 0; Ext.Array.each (arguments, function (value) { sum + = value; }); return sum;}; SUM (1, 2, 3); Returns 6
The iteration can stopped by returning false in the function callback.//End the iteration by setting the return value false.
Ext.each is alias for ext.array.each// the Ext.each method is the alias of the Ext.Array.each.
Parameter description:
iterable : Is the object you want to iterate over, and if it is not, it is executed only once.
fn: A callback function that executes once while traversing, and the function contains three parameters
Item, which is the value of each traversal
Index, the ordinal of the current value, index
AllItems: Is the current array object itself.
return value:
return FALSE when you want to end it.
Example Demo:
1. Use cmd to generate a default program
2. Modify the OnClickButton method in Maincontroller.js under the \app\view\main folder.
As follows:
Onclickbutton:function () { //ext.msg.confirm (' Confirm ', ' is sure? ', ' onconfirm ', this); var Studentsjson = {
student:[{ name: ' Zhang San ', studentid:200801, grade:80 },{ name: ' John Doe ', studentid:200802, grade:90 },{ name: ' Harry ', studentid:200803, grade:90 },{ name: ' Lee Leper ', studentid:200804, grade:90 }] }; Ext.each (studentsjson.student, function (student, index) {alert (student.name); if (Student.studentid = = ' 200803 ') {alert (' Next is the Lee, but I won't let him show it '); return false; Set Exit }});
The display results are as follows:
After clicking the button:
The last is:
[ExtJS5 Study notes] section 13th EXTJS5 Ext.each Method Learning