Ich habe eine Klasse in Ecmascript 6. Ich muss einen Wert von "this" an einen Rückruf übergeben.pass 'dies' auf Callback in einer Klasse ecmascript 6
Ich versuchte mit .bind (this). Bis jetzt scheint das nicht zu funktionieren. Ich habe auch versucht, var_this = this; und benutze _this innerhalb des Callbacks. es funktioniert immer noch nicht
class Modal {
constructor(modal) {
this._modal = modal;
this.id = this._options.id;
}
}
open(opts) {
let modalOptions = {
size: opts.size || '',
templateUrl: 'modal.html',
controller: function controller($scope, $uibModalInstance) {
var _this = this;
this._options = {
id: opts.id
};
this.hcbuttons: [{id: '1', name: 'test'}, {id: '2', name: 'abc'}];
publisher.subscribe('triggered', this._options.id, function(event, creator) {
//as soon as we subscribe to the published event
var result = this.hcbuttons.filter(function(obj) {
return obj.id == creator;
})[0];
if(result.sync === true) {
console.log('disabledall');
}
}).bind(this);
}
}
Was möchten Sie, dass dies zu sein? –
die modalinstance, im Grunde möchte ich 'this.hcbuttons' an den Rückruf – looneytunes
@looneytunes übergeben, bitte zuerst die Einrückung und die Klammern, dann erklären, was Sie dort tatsächlich gebaut haben. Dann können wir auf der gleichen Ebene sprechen – Thomas