本来想利用装试者来监听数据更改. 代码如下:export function fireBind(type:string) { return function (taget:any, key:string, descriptor:TypedPropertyDescriptor<any>) { let oldSet = descriptor.set;
descriptor.set = function(val){
MessageCenter.fire(new ModelEvent(type, val)); console.log('1111');
oldSet.call(null, val); console.log('2222');
}
}
}class Test { private _selected; @fireBind(EventState.GOODS_SELECTED) public set selected(data:any) { this._selectedData = data; console.log('this._selectedData:', this._selectedData);
} public get selected(){ return this._selectedData;
}
}调用 :const T = new Test();
T.selected = 'test';console.log(T.selected);输出结果:1111this._selectedData: testnull;
添加回答
举报
0/150
提交
取消