在我的项目中,当用户更改另一个列表中的选定值时,我有时希望更新列表中的可用选项。为此,我使用了valueChanges运算符pipe,switchMap如下所示:
this.form.controls.typeControl.valueChanges
.pipe(
switchMap((typeId: number) => {
return this.typesService.getProjectsByType(typeId);
}),
)
.subscribe((projects) => {
//...
});
Run Code Online (Sandbox Code Playgroud)
现在我遇到的问题是,我需要一次执行两个 http 请求来更新多个列表,而不是仅更新一个列表。当我尝试添加第二个时switchMap,我得到error TS2345: Argument of type 'OperatorFunction<number, Project[]>' is not assignable to parameter of type 'OperatorFunction<any, number>'.以下是我尝试执行此操作的方法:
this.form.controls.typeControl.valueChanges
.pipe(
switchMap((typeId: number) => {
return this.typesService.getProjectsByType(typeId);
}),
switchMap((typeId: number) => {
return this.typesService.getProgramsByType(typeId);
}),
)
.subscribe(([projects, programs]) => {
//...
});
Run Code Online (Sandbox Code Playgroud)
如何在此处添加第二个 http 请求,以便我可以处理 中两个请求收到的数据subscribe?
我有点新来反应并试图了解如何使 MQTT 与之一起工作。
我尝试按照此处发布的代码示例进行操作:https : //www.npmjs.com/package/mqtt-react
但没有成功。出于某种原因,它只是什么都不做。
这是我的代码:
App.js 类:
import React, { Component } from 'react';
import './App.css';
import PostMqtt from './PostMessage.js';
import {Connector} from "mqtt-react";
class App extends Component {
render() {
return (
<div className="App">
<PostMqtt/>
</div>
);
}
}
export default () => (
<Connector mqttProps="ws://test.mosquitto.org/">
<App />
</Connector>
);
Run Code Online (Sandbox Code Playgroud)
PostMessage.js 类:
import React from 'react';
import { subscribe } from 'mqtt-react';
export class PostMessage extends React.Component {
sendMessage(e) {
e.preventDefault();
//MQTT client is passed …Run Code Online (Sandbox Code Playgroud) when using tap we have 3 sections: event, error, complete.
the complete section will be triggered only if no error occurred on the way. is there a way to guarantee that the complete section will run no matter what (like finally in exception handling)?
tap(ev => console.log('event: ', ev)
err => console.log('error:', err),
() => console.log('guaranteed section?') );
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 angular material 选项卡组件达到以下结果: 
到目前为止我尝试过但没有成功的是使用带有 margin-left: auto 的 flex 属性,它应该将特定项目一直推到右边。
在此处添加我的代码:
<mat-tab-group>
<mat-tab label="Top 5"></mat-tab>
<mat-tab label="All Drivers"> Content 2</mat-tab>
<mat-tab style="margin-left: auto" label="All Drivers"> Content 3</mat-tab>
</mat-tab-group>
Run Code Online (Sandbox Code Playgroud)
在检查工具上,我设法使用 margin-left: auto 但不在 CSS 文件中实现了这一点。
有什么建议?
据我所知,在java中实现的HashMap中put/get操作的最坏情况是o(n).
在研究我正在研究的项目的高效数据结构时,我在这里看到了一个评论,在java 8 JDK中,那些操作的HashMap复杂性是O(logn),但我找不到文档关于它.这是真的,所以我可以依靠它吗?
如果这真的是事实,它是如何实现的?我的猜测是HashMap中的每个"单元格"都是作为平衡树实现的.
我做了一个菜单栏,当我点击帮助>>关于弹出窗口跳转.我还在弹出窗口中放了一个按钮,我想知道我应该使用什么命令来关闭按钮动作监听器中的弹出窗口,但不会中止程序.(我之前尝试使用(System.exit(0)),但它中止了程序.
我正在编写 ac 程序,我注意到每当我用 const 变量(const size_t MAX_LEN = some number)声明我的数组长度时,它都会向我发送错误。另一方面,当我使用 (#define MAX_LEN = some number ) 作为我的数组长度声明时,它工作得很好。
我得到的确切错误: LinSeperator.c:45:2: 错误:使用可变长度数组 'arr' [-Werror=vla] double theAns, arr[MAX_LEN]; ^
谁能帮我弄清楚为什么会这样?
编辑:这是我的代码:这是我的 LinSeperatorHelperFunc.h:
#pragma once
#include <stdio.h>
const size_t MAX_LEN = 199;
typedef struct Orange
{
double arr[MAX_LEN];
int tag;
}orange;
void learnProg(orange *o, double w[], int d);
void filePrinter(const char *output, FILE **fileIn, int d, double w[]);
Run Code Online (Sandbox Code Playgroud)
这是我的 .c 文件:
#include "LinSeperator.h"
#include "LinSeperatorHelperFunctions.h"
#define NEG_ONE (-1)
#define NegToPos (2)
void LinSeperator(const …Run Code Online (Sandbox Code Playgroud)