How to use compactArray method in storybook-root

Best JavaScript code snippet using storybook-root

ViolenceSearch.js

Source:ViolenceSearch.js Github

copy

Full Screen

1/**2 * Created on 2011-12-153 * @author: willian12345@126.com4 * @desc: 匹配输入框内输入的数据排序后返回数组5 * @version: 1.06 * 1.1 添加向服务器请求列表数据的功能 by wangyuefei7 * 1.2 延时向服务器请求数据 by wangyuefei8 * 1.3 修复过滤关键字重复时,返回数据完全一致的bug by chengtingting9 * @eg:10 * ViolenceSearch.init(options);11 * @param1 12 * {13 * input: 你的输入框,14 * 15 * resource: 你的资源(json格式)16 例如: 17 [{"avatar":"\/misc\/images\/avatars\/0T15420K-7.jpg","userid":"2012","username":"\u72d7\u5b50\u4e8c","location":"\u6d59\u6c5f\u676d\u5dde"},{"avatar":"\/misc\/images\/avatars\/16.jpg","userid":"2013","username":"\u4e8c\u72d7\u5b50","location":"\u6d59\u6c5f\u676d\u5dde"},{"avatar":"\/misc\/images\/avatars\/01135553C-27.jpg","userid":"2014","username":"\u72d7\u72d7\u4e8c\u5b50","location":"\u6d59\u6c5f\u676d\u5dde"}]18 *19 * filter: 已选择的数据父容器20 * filterWord: 过滤关键字21 * filterKey: 过滤数据项的唯一id22 * isFilterSelected: 是否过滤,23 * callback: 回调函数中会返回排序后的数据(对象)24 * descend: 是否降序排序25 * searchUrl:添加向服务器请求列表数据的url by wangyuefei26 * delayTime:延时请求时间27 * }28 * 29 * callback函数表达式结果返回参数数组 [Object{index:序号,item:{原json对象}}]30 */31;if(typeof ViolenceSearch == 'undefined'){32 ViolenceSearch = {};33}34ViolenceSearch.init = function(options){35 return new SEARCHER(options);36}37function SEARCHER(options){38 this.currentInput = options.input;39 this.resource = options.resource;40 this.originResource = [].concat(this.resource); //得到一个新对象41 this.filter = options.filter;42 this.filterWord = options.filterWord;43 this.filterKey = options.filterKey;44 this.isFilterSelected = options.isFilterSelected;45 this.callback = options.callback;46 this.searchUrl = options.searchUrl;47 this.delayTime = options.delayTime|1;48 this.descend = (options.descend == 'undefined' || options.descend == false) ? false : true;49 this.compactArray = [];50 this.bindChangeEvent();//input发生改变(兼容浏览器)51};52SEARCHER.prototype = {53 onInputChanged: function(_value){54 var that = this;55 var json={};56 json.keyword=_value;57 if(_value != ''){58 if(that.searchUrl){59 $.djax({60 url:that.searchUrl,61 data:json,62 type:'GET',63 dataType:'jsonp',64 success:function(data){65 that.callback(data);66 }67 })68 }else{69 that.getCompactData(_value);70 }71 }else{72 if(that.searchUrl){73 $.djax({74 url:that.searchUrl,75 data:json,76 type:'GET',77 dataType:'jsonp',78 success:function(data){79 that.callback(data);80 }81 })82 }else{83 that.callback();84 }85 }86 },87 bindChangeEvent: function(){ 88 var that = this,time;89 /**当用户在<发送到信息框>中输入时实时匹配显示输入**/90 $(that.currentInput).bind($.browser.opera ? "input" : "keyup", function(e){91 if(e.keyCode != 40 && e.keyCode != 38 && e.keyCode != 13){92 var $this=$(this);93 if(time){94 clearTimeout(time);95 }96 time = setTimeout(function(){97 that.onInputChanged($.trim($this.val()));98 },that.delayTime);99 }100 });101 },102 compare: function(object1,object2){103 if(object1.index > object2.index) return 1;104 else if(object1.index < object2.index) return -1;105 else return 0;106 },107 getSelected_userids: function(){//获得已选择的数据id108 var filterIDs = [];109 var spans = $(this.filter).find('span');110 var spansLength = spans.length;111 for(var i=0;i < spansLength; i++){112 filterIDs.push($(spans[i]).attr('rel'));113 }114 return filterIDs;115 },116 getCompactData: function(_value){117 var that = this;118 var value = _value;119 120 that.compactArray.length = 0;121 122 for(var i=0, len = that.resource.length; i< len; i++){//为所有数据项加上visible属性用于过滤与还原123 that.resource[i].visible = true;124 }125 126 if(that.isFilterSelected){//是否过滤已添加的数据127 var filterIDs = that.getSelected_userids(); 128 var len=$(that.filter).find('span').length;129 for(var i=0; i < len; i++){130 var num = that.resource.length - 1;131 that.resource[num].visible = true;132 }133 for(var i=0; i < len; i++){//过滤已经选择的数据134 var num = that.resource.length - 1;135 while(num >= 0){136 if(filterIDs[i] == that.resource[num][that.filterKey]){137 that.resource[num].visible = false;138 }139 num--;140 }141 }142 }143 that.compactArray.length = 0;144 for(var i=0, len = that.resource.length; i< len; i++){//匹配查找到匹配并且可见的数据项145 var currentItem = that.resource[i];146 var _index = currentItem[that.filterWord].indexOf(_value);147 if(_index >= 0 && currentItem.visible){148 var object = {};149 object.index = _index;150 object.item = currentItem;151 that.compactArray.push(object);152 }153 }154 155 if(that.compactArray.length > 0){156 that.compactArray.sort(that.compare);157 if(that.descend){158 that.compactArray.reverse();159 }160 }161 var temp = {};162 var arr = [];163 var arr1 = [];164 165 //修复过滤关键字重复时,返回数据完全一致的bug by chengtingting166 $.each(that.compactArray,function(i,o){167 temp[o.item[that.filterKey]] = o;168 temp[o.item[that.filterKey]].ischecked = false; //当关键子有重复时,用ischecked判断,避免重复插入169 arr.push(o.item[this.filterWord]);170 });171 arr = arr.sort(); //按关键字排序172 $.each(arr,function(i,o){ //o关键字173 for(var i in temp){174 if(o === temp[i].item[this.filterWord] && !temp[i].ischecked){175 arr1.push(temp[i]);176 temp[i].ischecked = true;177 }178 }179 })180 that.callback(arr1);181 }...

Full Screen

Full Screen

compact-array.js

Source:compact-array.js Github

copy

Full Screen

...26 }27 function filter(col, fn) {28 return col.filter(fn);29 }30 function compactArray(o) {31 var ret = [];32 if (isArray(o)) {33 for (var i = 0; i < o.length; i++) {34 if (!isEmpty(o[i])) {35 if (isArray(o[i])) {36 ret.push(compactArray(o[i]));37 } else {38 ret.push(o[i]);39 }40 }41 }42 }43 return ret;44 }45 if (typeof exports !== 'undefined') {46 if (typeof module !== 'undefined' && module.exports) {47 exports = module.exports = compactArray;48 }49 exports.compactArray = compactArray;50 } else if (typeof define === 'function' && define.amd) {...

Full Screen

Full Screen

compact-array.spec.ts

Source:compact-array.spec.ts Github

copy

Full Screen

1import { compactArray } from '@terminus/fe-utilities';2describe(`compactArray`, function() {3 test(`should return undefined if the array is empty or doesn't exist`, () => {4 expect(compactArray(null as any)).toEqual(undefined);5 expect(compactArray([])).toEqual(undefined);6 });7 test(`should return the cleaned array`, () => {8 const arr1: any[] = ['foo', null, 'bar', undefined, 'baz'];9 expect(compactArray<string>(arr1)).toEqual(['foo', 'bar', 'baz']);10 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { compactArray } from 'storybook-root';2import { compactArray } from 'storybook-root';3import { compactArray } from 'storybook-root';4import { compactArray } from 'storybook-root';5import { compactArray } from 'storybook-root';6import { compactArray } from 'storybook-root';7import { compactArray } from 'storybook-root';8import { compactArray } from 'storybook-root';9import { compactArray } from 'storybook-root';10import { compactArray } from 'storybook-root';11import { compactArray } from 'storybook-root';12import { compactArray } from 'storybook-root';13import { compactArray } from 'storybook-root';14import { compactArray } from 'storybook-root';15import { compactArray } from 'storybook-root';16import { compactArray } from 'storybook-root';17import { compactArray } from 'storybook-root';18import { compactArray } from

Full Screen

Using AI Code Generation

copy

Full Screen

1import { compactArray } from 'storybook-root';2import { compactArray } from 'storybook-root';3import { compactArray } from 'storybook-root';4import { compactArray } from 'storybook-root';5import { compactArray } from 'storybook-root';6import { compactArray } from 'storybook-root';7import { compactArray } from 'storybook-root';8import { compactArray } from 'storybook-root';9import { compactArray } from 'storybook-root';10import { compactArray } from 'storybook-root';11import { compactArray } from 'storybook-root';12import { compactArray } from 'storybook-root';13import { compactArray } from 'storybook-root';14import { compactArray } from 'storybook-root';15import { compactArray } from 'storybook-root';16import { compactArray } from 'storybook-root';17import { compactArray } from 'storybook-root';18import { compactArray } from 'storybook-root';19import { compactArray } from 'storybook-root';20import { compactArray } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { compactArray } from 'storybook-root';2import { compactArray } from 'storybook-root';3import { compactArray } from 'storybook-root';4import { compactArray } from 'storybook-root';5import { compactArray } from 'storybook-root';6import { compactArray } from 'storybook-root';7import { compactArray } from 'storybook-root';8import { compactArray } from 'storybook-root';9import { compactArray } from 'storybook-root';10import { compactArray } from 'storybook-root';11import { compactArray } from 'storybook-root';12import { compactArray } from 'storybook-root';13import { compactArray } from 'storybook-root';

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful