@angular-jz/jz
Version:
jim jz
116 lines • 5.03 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var forms_1 = require("@angular/forms");
var JZMultipleSelectComponent = /** @class */ (function () {
function JZMultipleSelectComponent() {
this.idField = 'id';
this.textField = 'text';
this.placeholder = '请选择';
this._value = [];
this.propagateChange = function (_) { };
}
JZMultipleSelectComponent_1 = JZMultipleSelectComponent;
JZMultipleSelectComponent.prototype.ngOnInit = function () {
var me = this;
$(this.select.nativeElement).on('change', function (e) {
var idType = null;
if (me.items && me.items.length) {
idType = typeof (me.items[0][me.idField]);
}
var newValue = $(me.select.nativeElement).val();
newValue = newValue.map(function (item) {
if (idType == null)
return item;
else if (idType == "number")
return Number(item);
else if (idType == "string")
return String(item);
else if (idType == "object")
return item;
});
me._value = newValue;
me.propagateChange(me.value);
});
};
JZMultipleSelectComponent.prototype.ngOnDestroy = function () {
$(this.select.nativeElement).off('change');
};
JZMultipleSelectComponent.prototype.ngAfterViewInit = function () {
$(this.select.nativeElement).select2({
placeholder: this.placeholder
});
};
Object.defineProperty(JZMultipleSelectComponent.prototype, "value", {
get: function () {
return this._value;
},
set: function (value) {
if (this._value != value) {
this._value = value;
this.propagateChange(this.value);
$(this.select.nativeElement).val(this._value);
$(this.select.nativeElement).trigger('change');
}
},
enumerable: true,
configurable: true
});
JZMultipleSelectComponent.prototype.writeValue = function (value) {
this.value = value;
};
JZMultipleSelectComponent.prototype.registerOnChange = function (fn) {
this.propagateChange = fn;
};
JZMultipleSelectComponent.prototype.registerOnTouched = function (fn) { };
__decorate([
core_1.ViewChild('select'),
__metadata("design:type", core_1.ElementRef)
], JZMultipleSelectComponent.prototype, "select", void 0);
__decorate([
core_1.Input(),
__metadata("design:type", Array)
], JZMultipleSelectComponent.prototype, "items", void 0);
__decorate([
core_1.Input(),
__metadata("design:type", String)
], JZMultipleSelectComponent.prototype, "idField", void 0);
__decorate([
core_1.Input(),
__metadata("design:type", String)
], JZMultipleSelectComponent.prototype, "textField", void 0);
__decorate([
core_1.Input(),
__metadata("design:type", String)
], JZMultipleSelectComponent.prototype, "placeholder", void 0);
__decorate([
core_1.Input(),
__metadata("design:type", Array)
], JZMultipleSelectComponent.prototype, "_value", void 0);
JZMultipleSelectComponent = JZMultipleSelectComponent_1 = __decorate([
core_1.Component({
selector: 'jz-multiple-select',
templateUrl: './jz-multiple-select.component.html',
providers: [{
provide: forms_1.NG_VALUE_ACCESSOR,
/* tslint:disable */
useExisting: core_1.forwardRef(function () { return JZMultipleSelectComponent_1; }),
/* tslint:enable */
multi: true
}],
})
], JZMultipleSelectComponent);
return JZMultipleSelectComponent;
var JZMultipleSelectComponent_1;
}());
exports.JZMultipleSelectComponent = JZMultipleSelectComponent;
//# sourceMappingURL=jz-multiple-select.component.js.map