js去重
function uniqueDis ( arr, type) {
var hash = { } ;
var result = [ ] ;
for ( var i = 0 , len = arr. length; i < len; i++ ) {
if ( ! hash[ arr[ i] [ type] ] ) {
result. push ( arr[ i] ) ;
hash[ arr[ i] [ type] ] = true ;
}
}
return result;
}
function ditinct ( array, type) {
var obj = { } ;
return array. reduce ( function ( item, next) {
obj[ next[ type] ] ? '' : obj[ next[ type] ] = true && item. push ( next) ;
return item;
} , [ ] ) ;
}
js排序
array. sort ( function ( a, b) {
return a. factoryName. localeCompare ( b. factoryName) ;
} ) ;
js搜索
$ ( "#factoryName" ) . keyup ( function ( ) {
let factoryid= '' ;
let factoryName= '' ;
let searchName= $ ( "#factoryName" ) . val ( ) . split ( /[,,;;]/g ) ;
let _input_check = $ ( ".select input[checkbox-type='factory']" ) ;
if ( ! ( $ ( "#factoryName" ) . val ( ) ) ) {
$ ( "#factory" ) . val ( '' ) ;
_input_check. parent ( ) . siblings ( ) . show ( ) ;
_input_check. each ( function ( i) {
$ ( this ) . prop ( "checked" , false ) ;
} ) ;
return ;
}
_input_check. parent ( ) . siblings ( ) . hide ( ) ;
_input_check. each ( function ( i) {
factoryName = $ ( this ) . parent ( ) . contents ( ) . filter ( function ( ) {
return this . nodeType == 3 ;
} ) . text ( ) ;
let _this= $ ( this ) ;
for ( let i= 0 ; i< searchName. length; i++ ) {
if ( factoryName. indexOf ( searchName[ i] ) > - 1 ) {
_this. parent ( ) . show ( ) ;
}
}
} ) ;
} ) ;