我有对象数组,我只取位置数组。我的目标是将这些位置数组合并为一个数组,但是我没有这样做并得到空数组。这就是我的做法:
let results = [{
id: '1',
locations: ['aaaa', 'bbbbbb', 'cccccc']
},
{
id: '2',
locations: []
},
{
id: '3',
locations: ['ddd', 'aaadsad', 'sefd']
},
{
id: '4',
locations: ['ffff', 'eeee', 'sfdsfsd']
},
];
const locationIds = [].concat.apply([], ...results.filter(s => s.locations && s.locations.length > 0).map(({
locations
}) => ({
locations
})));
console.log(locationIds);Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?结果应该是
['aaaa', 'bbbbbb', 'cccccc', 'ddd', 'aaadsad', 'sefd', 'ffff', 'eeee', 'sfdsfsd'];
我必须比较表,但有一些列我不需要比较,我只知道它们(不是我必须比较的那些)所以我想从表中选择所有列,除了我不需要的列比较。
我想到了这样的事情:
SELECT 'SELECT ' || array_to_string(ARRAY(SELECT 'o' || '.' || c.column_name
FROM information_schema.columns As c
WHERE table_name = 'office'
AND c.column_name NOT IN('id', 'deleted')
), ',') || ' FROM officeAs o' As sqlstmt
Run Code Online (Sandbox Code Playgroud)
但是输出SELECT * FROM office As o
不是select a,b,c from office没有id and deleted列。
有没有人知道这个查询有什么问题?
生产构建后如何保留源映射?
现在,我的命令如下所示:
"build-prod": "ng build --app=release -prod && cp -R lang dist"
我尝试将其更改为:
ng build --app=release --sourceMap=true -prod && cp -R lang dist
但什么都没有改变。
如果我这样做:
ng build --sourcemap我得到了源映射,但随后我得到了 index.html 而不是 index.prod.html。
是否可以编辑第一个命令来构建源映射文件?
这是我的tsconfig.json文件:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}Run Code Online (Sandbox Code Playgroud)
我有一个看起来像这样的对象:
peaks =
0: {intervalId: 7, time: 1520290800000, value: 54.95125000000001}
1: {intervalId: 7, time: 1520377200000, value: 49.01083333333333}
Run Code Online (Sandbox Code Playgroud)
等等。
我如何发现peak它Max有价值?我试着这样做
this.loadPeak = peaks.map(a => Math.max(a.value));
Run Code Online (Sandbox Code Playgroud)
但我只是得到了一堆峰值数组value(而不是所有的 intervalId、时间、值)而不是最大值。
**非常感谢大家,每个解决方案都有效,遗憾的是不能全部接受。**
我安装了 vscode-test-explorer 扩展以及它的子 angular-karma-test-explorer 和 jasmine-test-adapter 到我的 vscode (如这里所回答的Karma run single test)
但是,没有测试加载到测试资源管理器,它显示这些项目可供选择,但没有加载:

我的 angular-cli.json:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "frontend-cli"
},
"apps": [
{
"name": "debug",
"root": "src",
"outDir": "dist",
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
],
"environmentSource": "app/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
},
{
"name": "release",
"root": "src",
"outDir": "dist",
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": …Run Code Online (Sandbox Code Playgroud)假设我创建这样的对象:
updates.push({
id: this.ids[i],
point: point,
value: value
});
Run Code Online (Sandbox Code Playgroud)
后来我想在对象JSON.stringify上使用updates,但是我只需要
point并且value 喜欢:
updates[{point: 1, value: 12}, {point: 2, value: 24}]
Run Code Online (Sandbox Code Playgroud)
最好的 ES6 解决方案是什么?
我查看了一些带有删除的示例,但这不是我真正需要的,因为我不想删除 ids。
我一直在尝试将 xls(或任何其他)文件从我的 angular 应用程序发送到 .NET 核心控制器。我尝试了很多方法,但没有一个奏效...
这是我的组件,点击按钮我调用我的服务:
handleFileInput(file: FileList) {
this.fileToUpload = file.item(0);
const url = 'http://localhost:44328/api/Student';
this.studentService.postFile(this.url, this.fileToUpload)
.subscribe((res: any) => {
},
(err) => {
if (err.status === 401) {
} else {
}
});
Run Code Online (Sandbox Code Playgroud)
}
这是服务方法:
postFile(url: string, fileToUpload: File): Observable<Response> {
const formData: FormData = new FormData();
formData.append('File', fileToUpload, fileToUpload.name);
const headers = new Headers();
headers.append('Content-Type', 'multipart/form-data');
headers.append('Accept', 'application/json');
const options = new RequestOptions({ headers });
return this.http.post(url, formData, options);
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
[Route("/api/[controller]")]
public class StudentController …Run Code Online (Sandbox Code Playgroud) 我根本不知道如何解决这个问题,我已经坐在那里好几个小时了,什么也没发生。

从我的角度来看,我像这样使用 http.post :
function PostReview(JSONObject) {
if(JSONObject!=null){
$http({
url: 'http://localhost:8000/creation',
method: "POST",
data: JSONObject,
headers: { "Content-Type": "application/json"} });
}
}
Run Code Online (Sandbox Code Playgroud)
在 php 中我尝试这样得到它:
public function created()
{
$json = file_get_contents('php://input');
$request = json_decode($json);
var_dump($request);
// $email = $request->email;
//return response()->json($request);
}
Run Code Online (Sandbox Code Playgroud)
我还有 Cors 类,我在其中处理 OPTIONS 预检问题。我尝试在那里添加标题,但没有运气:
class CorsMiddleware {
protected $settings = [
'origin' => '*', // Wide Open!
'allowMethods' => 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
'allowHeaders' => 'Content-Type, Origin'];
protected function setOrigin($req, $rsp)
{
$origin = $this->settings['origin'];
if (is_callable($origin))
{
// …Run Code Online (Sandbox Code Playgroud) 我的数组中有 appsettings.json
"steps": [
{
"name": "IMPORT",
"enabled": true
},
{
"name": "IMPORT_XML",
"enabled": true
},
{
"name": "COMPARE",
"enabled": true
},
{
"test_name": "COMPARE_TABLE",
"enabled": true
}]
Run Code Online (Sandbox Code Playgroud)
在我的课堂上,我试图用 IConfigurationRoot _configurationRoot
我试过了:
var procSteps = _configurationRoot.GetSection("steps");
foreach (IConfigurationSection section in procSteps.GetChildren())
{
var key = section.GetValue<string>("test");
var value = section.GetValue<string>("enabled");
}
Run Code Online (Sandbox Code Playgroud)
和:
var procSteps = _configurationRoot.GetSection("ExecutionSteps")
.GetChildren()
.Select(x => x.Value)
.ToArray();
Run Code Online (Sandbox Code Playgroud)
但他们都没有找回我的价值观。有谁知道这是什么情况以及访问此类数组值的正确方法是什么?
我想输入一个具有三种状态的输入框:选中,未选中和划线(又名失败)当前,我能够进行选中/取消选中并相应地更改计算
<input type="checkbox" [ngStyle]="{content: expression}" *ngIf="milestone?.description" [checked]="milestone?.status == 'checked'" (change)="checkMilestone(milestone,initiative, $event, '')">Run Code Online (Sandbox Code Playgroud)
但是,我很难添加crossed(X)复选框。有谁知道应该怎么做?我是否应该声明如下内容:
states = [
{ id: 0, status: 'checked'},
{ id: 1, status: 'unchecked'},
{ id: 2, status: 'crossed'}
];
Run Code Online (Sandbox Code Playgroud)
并添加样式并相应地进行更改?我不确定如何添加三种样式,而不是两种。
typescript ×6
javascript ×5
angular ×4
c# ×2
json ×2
.net ×1
angular-cli ×1
angularjs ×1
appsettings ×1
arrays ×1
asp.net ×1
asp.net-core ×1
checkbox ×1
css ×1
jasmine ×1
karma-runner ×1
node.js ×1
php ×1
postgresql ×1
sql ×1