我正在使用 angular/rxjs6 构建一个简单的秒表,我可以启动计时器,但无法暂停/恢复它。
source: Observable<number>;
subscribe: Subscription;
start() {
this.source = timer(0, 1000);
this.subscribe = this.source
.subscribe(number => {
this.toSeconds = number % 60;
this.toMinutes = Math.floor(number / 60);
this.toHours = Math.floor(number / (60 * 60));
this.seconds = (this.toSeconds < 10 ? '0' : '') + this.toSeconds;
this.minutes = (this.toMinutes < 10 ? '0' : '') + this.toMinutes;
this.hours = (this.toHours < 10 ? '0' : '') + this.toHours;
});
}
pause() {
this.subscribe.unsubscribe(); // not working
}
Run Code Online (Sandbox Code Playgroud)
经过大量搜索后,我发现我应该使用switchMap …
我想转换这个多维数组:
array(
[0] => array (
"interest_income-bank" => "520.541"
"total_interest_expense" => "145.791"
"net_interest_income" => "434.937"
"loan_loss_provision" => "135.664"
.
.
)
[1] => array (
"interest_income-bank" => "617.894"
"total_interest_expense" => "205.508"
"net_interest_income" => "506.510"
"loan_loss_provision" => "120.586"
.
.
)
)
Run Code Online (Sandbox Code Playgroud)
到这样的数组:
array(
[interest_income-bank] => array (
"0" => "520.541"
"1" => "617.894"
.
.
)
[total_interest_expense] => array (
"1" => "145.791"
"2" => "205.508"
.
.
)
)
Run Code Online (Sandbox Code Playgroud)
尝试了很多但没有运气:(
任何帮助将非常感激!