Произошла ошибка.
Пожалуйста, обновите страницу.
Fly.js > Документация > Коллекции > $(...).map()

$(...).map()

Возвращает новую FlyNode, сформированную из результатов функции-итератора.

#Коллекции

$(...).map(iterator, [context])

                    FlyDomNode: {
                        __constructor: function(context) {
                            var array = fnNodeList.makeDomNodeArray(context);
                            for (var a = 0, al = array.length; a < al; a++) {
                                this[a] = array[a];
                            }
                            this.length = al;
                        },

                        size: function() {
                            return this.length;
                        },

                        get: function(index) {
                            return $.isNumber(index) ? this[index] : [].slice.call(this);
                        },

                        addNode: function(flyNode) {
                            return fnNodeList.changeNodeContext(this, flyNode, function(child, context) {
                                context.indexOf(child) === -1 && context.push(child);
                            });
                        },

                        removeNode: function(flyNode) {
                            return fnNodeList.changeNodeContext(this, flyNode, function(child, context) {
                                var position = context.indexOf(child);
                                if (position !== -1) context.splice(position, 1);
                            });
                        },

                        eq: function(index) {
                            if (index < 0) index = index + this.length;
                            return new this.__self(this[index]);
                        },

                        lt: function(index) {
                            return new this.__self(this.slice(0, index));
                        },

                        gt: function(index) {
                            return new this.__self(this.slice(index));
                        },

                        last: function(selector) {
                            var element = this[this.length - 1];
                            return new this.__self(fnStyle.isMatch(element, selector) ? element : []);
                        },

                        first: function(selector) {
                            var element = this[0];
                            return new this.__self(fnStyle.isMatch(element, selector) ? element : []);
                        },

                        normalize: function() {
                            return fnNodeList.transformNodeContext(this, function(item, context) {
                                if ($.isNode(item)) context.push(item);
                            });
                        },

                        each: function(callback, context) {
                            $.each(this, callback, context);
                            return this;
                        },

                        name: function() {
                            return this[0].tagName.toLowerCase() || null;
                        }
                    }
                

$(...).map(iterator, [context])
Возвращает: FlyNode [$]

Возвращает новую FlyNode, сформированную из результатов функции-итератора.

iterator: Function ()

Функция-итератор, возвращающая DOM узел.

context: Any *

Контекст выполнения функции-итератора.

Обратите внимание, что в результирующую FlyNode попадут только DOM узлы, поэтому нет никакого смысла для итератора возвращать другие значения.

Пример: Создание новой FlyNode с помощью $(...).map.

<!DOCTYPE html>
    <head>
        <meta charset="utf-8"/>
        <title>Fly.js - $(...).map()</title>

        <script src="/scripts/fly.js"></script>
    </head>
    <body>
        <p class="up">Child of body.</p>
        <p class="up">Child of body.</p>
        <p class="down">
            <span>Child of paragraph!</span>
        <p>

        <script>
            $('p').map(function(p) {
                var $p = $(p);
                if ($p.hasClass('up')) {
                    return $p.parent();
                } else {
                    return $p.children();
                }
            }).css('border', '2px red solid');
        </script>
    </body>
</html>