问题描述
将附上此任务的完整示例mock.js unsubscribe。我有一个商店化约器(tbodyCommand.reducer.js),需要通过订阅从数据中获取10行,然后才需要取消订阅。我正在使用标准的.unsubscribe()
方法,但是转到了TypeError _mock.default.unsubscribe is not a function
。如何关闭我的订阅?
我在unsubscribe is not a function on an observable处发现了类似的问题,其中主要问题出现在RxJS版本中,但我的情况似乎对我有用。此处使用subscribe方法构造语法的示例不包含任何处理mock.js的方法。如何在示例中使用它,使其可以正常工作?还有其他方法可以更简单地解决此问题吗?
解决方法
更改了属性$。订阅变量,并从订阅函数中取出收益。
var row_temp = [];
const makeTbodyArray = () => {
properties$.subscribe((data) => { // this stuff need to go in variable
if (row_temp.length < 11) {
row_temp.push(data);
} else {
properties$.unsubscribe();
return row_temp; // taking out return
}
});
};
至
var row_temp = [];
const makeTbodyArray = () => {
let subscription = properties$.subscribe((data) => {
if (row_temp.length < 11) {
row_temp.push(data);
} else {
subscription.unsubscribe();
}
});
return row_temp; // like that
};