ace-component
Version:
ace-components for ewms
94 lines (79 loc) • 2.61 kB
text/typescript
import { Component, OnInit, ViewEncapsulation, Input, Output, EventEmitter, AfterViewInit,
OnDestroy, ElementRef, OnChanges } from '@angular/core';
import dropdownSelect from './dropdownSelect.min.js';
import * as $ from 'jquery'
export class AceDropdownselectComponent implements AfterViewInit, OnDestroy, OnChanges {
constructor(
public el:ElementRef
) {
var num: string = "";
for (var i = 0; i < 10; i++) {
num = num + Math.floor(Math.random() * 10)
}
this.eleId = "ace-dropdown" + num;
}
dataSource: Array<any> = [];//传进来的数据
paging:boolean = true; //是否有翻页
multiple: boolean = false; //多选
width: number = 200; //宽度
visCount: number = 5; //每页的可视数据
pageSize: number = 10; //每页的总数据
placeholder: string = '点击下拉选择'; //设置placeholder
public eleId: string; //节点id
public value: any; //选中的值
public _target: any; //实例
onChange = new EventEmitter();
InitDrowDown() {
this._target = new dropdownSelect("#" + this.eleId, {
data: this.dataSource,
multiple: this.multiple,
width: this.width,
visCount: this.visCount,
pageSize: this.pageSize,
triggerText: this.placeholder,
notFoundText: '无匹配记录',
onOptionClick: (value) => {
this.value = value;
this.onChange.emit(value);
},
afterSelect:(value)=>{
this.value = value;
}
});
this.setSelected();
}
ngAfterViewInit() {
this.InitDrowDown();
if(this.paging===false){
this.el.nativeElement.getElementsByClassName('select__page')[0].style.display = 'none';
}
}
setSelected(){
this._target.setSelect(function(row){
if(row.selected&&row.selected===true){
return true
}else{
return false
}
})
}
ngOnChanges(){
if(this._target&&this._target.length!=0){
this._target.setData(this.dataSource);
}
}
ngOnDestroy() {
this._target.destroy();
}
cleanValue() {
this._target.cleanValue();
this.value = undefined;
$(this.el.nativeElement).find('.select__triggerbar').removeClass('select__triggerbar-hasvalue');
}
}