當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript arr.arr_each函數代碼示例

本文整理匯總了TypeScript中@utils/arr.arr_each函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript arr_each函數的具體用法?TypeScript arr_each怎麽用?TypeScript arr_each使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了arr_each函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

	refresh: function(value, method, args, result){
		var i = 0,
			x, imax;
			
		var node = this.node,
			
			model = this.model,
			ctx = this.ctx,
			ctr = this.node
			;

		if (method == null) {
			// this was new array/object setter and not an immutable function call
			
			var compos = node.components;
			if (compos != null) {
				var imax = compos.length,
					i = -1;
				while ( ++i < imax ){
					if (compo_dispose(compos[i], node)){
						i--;
						imax--;
					}
				}
				compos.length = 0;
			}
			
			var frag = this._build(node, value, ctx, ctr);
			
			dom_insertBefore(frag, this.placeholder);
			arr_each(node.components, compo_inserted);
			return;
		}

		var array = value;
		arr_createRefs(value);
		

		switch (method) {
		case 'push':
			list_update(this, null, null, array.length - 1, array.slice(array.length - 1));
			break;
		case 'pop':
			list_update(this, array.length, 1);
			break;
		case 'unshift':
			list_update(this, null, null, 0, array.slice(0, 1));
			break;
		case 'shift':
			list_update(this, 0, 1);
			break;
		case 'splice':
			var sliceStart = args[0],
				sliceRemove = args.length === 1 ? this.components.length : args[1],
				sliceAdded = args.length > 2 ? array.slice(args[0], args.length - 2 + args[0]) : null;

			list_update(this, sliceStart, sliceRemove, sliceStart, sliceAdded);
			break;
		case 'sort':
		case 'reverse':
			list_sort(this, array);
			break;
		case 'remove':
			if (result != null && result.length) 
				list_remove(this, result);
			break;
		}
	},
開發者ID:atmajs,項目名稱:MaskJS,代碼行數:68,代碼來源:proto.ts

示例2: jMask

			return node
		});
		return jMask(result);
	},
	wrapAll: function(wrapper){
		var $wrap = jMask(wrapper);
		if ($wrap.length === 0){
			log_error('Not valid wrapper', wrapper);
			return this;
		}
		this.parent().mask($wrap);
		jmask_deepest($wrap[0]).nodes = this.toArray();
		return this.pushStack($wrap);
	}
};

arr_each(['empty', 'remove'], function(method) {
	ManipDom[method] = function(){
		return coll_each(this, Methods_[method]);
	};
	var Methods_ = {
		remove: function(node){
			if (node.parent != null) 
				coll_remove(node.parent.nodes, node);
		},
		empty: function(node){
			node.nodes = null;
		}
	};
});
開發者ID:atmajs,項目名稱:MaskJS,代碼行數:30,代碼來源:manip_dom.ts

示例3: arr_each

arr_each([
	'filter',
	'children',
	'closest',
	'parent',
	'find',
	'first',
	'last'
], function(method) {

	Traverse[method] = function(selector) {
		var result = [],
			matcher = selector == null
				? null
				: selector_parse(selector, this.type, method === 'closest' ? 'up' : 'down'),
			i, x;

		switch (method) {
		case 'filter':
			return jMask(jmask_filter(this, matcher));
		case 'children':
			var nextKey = selector_getNextKey(this);
			for (i = 0; i < this.length; i++) {
				x = this[i];
				var arr = x[nextKey];
				if (arr == null) {
					continue;
				}
				result = result.concat(matcher == null ? arr : jmask_filter(arr, matcher));
			}
			break;
		case 'parent':
			for (i = 0; i < this.length; i++) {
				x = this[i].parent;
				if (!x || x.type === Dom.FRAGMENT || (matcher && selector_match(x, matcher))) {
					continue;
				}
				result.push(x);
			}
			arr_unique(result);
			break;
		case 'closest':
		case 'find':
			if (matcher == null) {
				break;
			}
			for (i = 0; i < this.length; i++) {
				jmask_find(this[i][matcher.nextKey], matcher, result);
			}
			break;
		case 'first':
		case 'last':
			var index;
			for (i = 0; i < this.length; i++) {

				index = method === 'first' ? i : this.length - i - 1;
				x = this[index];
				if (matcher == null || selector_match(x, matcher)) {
					result[0] = x;
					break;
				}
			}
			break;
		}

		return this.pushStack(result);
	};

});
開發者ID:atmajs,項目名稱:MaskJS,代碼行數:69,代碼來源:traverse.ts

示例4: dom_removeAll

export function dom_removeAll (arr) {
    arr_each(arr, dom_removeElement);
};
開發者ID:atmajs,項目名稱:MaskJS,代碼行數:3,代碼來源:dom.ts

示例5: dom_showAll

export function dom_showAll (arr) {
    arr_each(arr, dom_showEl);
};
開發者ID:atmajs,項目名稱:MaskJS,代碼行數:3,代碼來源:dom.ts

示例6: dom_hideAll

export function dom_hideAll (arr) {
    arr_each(arr, dom_hideEl);
};
開發者ID:atmajs,項目名稱:MaskJS,代碼行數:3,代碼來源:dom.ts

示例7: arr_each

arr_each(['append', 'prepend'], function(method) {

	Proto[method] = function(mix) {
		var $mix = jMask(mix),
			i = 0,
			length = this.length,
			arr, node;

		for (; i < length; i++) {
			node = this[i];
			// we create each iteration a new array to prevent collisions in future manipulations
			arr = $mix.toArray();

			for (var j = 0, jmax = arr.length; j < jmax; j++) {
				arr[j].parent = node;
			}

			if (node.nodes == null) {
				node.nodes = arr;
				continue;
			}

			node.nodes = method === 'append' ? node.nodes.concat(arr) : arr.concat(node.nodes);
		}

		return this;
	};

});
開發者ID:atmajs,項目名稱:MaskJS,代碼行數:29,代碼來源:proto.ts

示例8: add

        if (has(node, klass) === false) 
            add(node, klass);
    },
    remove: function(node, klass){
        if (has(node, klass) === true) 
            remove(node, klass);
    },
    toggle: function(node, klass){
        var fn = has(node, klass) === true ? remove : add;
        fn(node, klass);
    }
};
arr_each(['add', 'remove', 'toggle'], function(method) {
    var fn = Mutator_[method];
    ManipClass[method + 'Class'] = function(klass) {
        return coll_each(this, function(node){
            fn(node, klass);
        });
    };
});
function current(node){
    var className = node.attr['class'];
    return typeof className === 'string' ? className : '';
}
function has(node, klass){
    return -1 !== (' ' + current(node) + ' ').indexOf(' ' + klass + ' ');
}
function add(node, klass){
    node.attr['class'] =  (current(node) + ' ' + klass).trim();
}
function remove(node, klass) {
    node.attr['class'] = (' ' + current(node) + ' ').replace(' ' + klass + ' ', '').trim();
開發者ID:atmajs,項目名稱:MaskJS,代碼行數:32,代碼來源:manip_class.ts


注:本文中的@utils/arr.arr_each函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。