@rdkmaster/jigsaw-labs
Version:
Jigsaw, the next generation component set for RDK
91 lines (72 loc) • 2.33 kB
text/typescript
import {AbstractJigsawComponent} from "../common";
import {EventEmitter, Input, Output} from "@angular/core";
import {ArrayCollection} from "../../core/data/array-collection";
import {GroupOptionValue} from "./group-common";
import {ControlValueAccessor} from "@angular/forms";
import {CommonUtils} from "../../core/utils/common-utils";
export class AbstractJigsawGroupLiteComponent extends AbstractJigsawComponent implements ControlValueAccessor {
public valid: boolean = true;
public data: ArrayCollection<GroupOptionValue> | GroupOptionValue[];
/**
* 设置对象的标识
*/
private _trackItemBy: string | string[];
public get trackItemBy(): string | string[] {
if (this.data && (typeof this.data[0] == 'string' || typeof this.data[0] == 'number')) {
this._trackItemBy = null;
} else if (CommonUtils.isUndefined(this._trackItemBy) && this.data && typeof this.data[0] !== 'string') {
this._trackItemBy = [this.labelField];
}
return this._trackItemBy;
}
public set trackItemBy(value: string | string[]) {
this._trackItemBy = typeof value === 'string' ? value.split(/\s*,\s*/g) : value;
}
/**
* 设置数据的显示字段
* @type {string}
*/
public labelField: string = 'label';
/**
* 多选开关
*
*/
public multipleSelect: boolean;
/**
* 选择的结果集
*
*/
public selectedItems: ArrayCollection<any> | any[];
/**
* 选择结果发生变化时,向外面发送事件
* @type {EventEmitter<any[]>}
*
*/
public selectedItemsChange = new EventEmitter<any[]>();
public get _$trackByFn() {
return CommonUtils.toTrackByFunction(this._trackItemBy);
};
/**
* @internal
*/
public _$handleSelectChange(items) {
this.selectedItemsChange.emit(items);
this._propagateChange(items);
}
ngOnInit() {
super.ngOnInit();
}
private _propagateChange: any = () => {
};
public writeValue(value: any): void {
}
public registerOnChange(fn: any): void {
this._propagateChange = fn;
}
public registerOnTouched(fn: any): void {
}
}