[ExtJS5 Study notes] section 13th EXTJS5 Ext.each Method Learning

Source: Internet
Author: User
Tags iterable

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.