如何使用JSONObject在Java中创建如下所示的JSON对象?
{
"employees": [
{"firstName": "John", "lastName": "Doe"},
{"firstName": "Anna", "lastName": "Smith"},
{"firstName": "Peter", "lastName": "Jones"}
],
"manager": [
{"firstName": "John", "lastName": "Doe"},
{"firstName": "Anna", "lastName": "Smith"},
{"firstName": "Peter", "lastName": "Jones"}
]
}
Run Code Online (Sandbox Code Playgroud)
我找到了很多例子,但不是我的JSONArray字符串.
我有如下情况:
myObservable1.pipe(
switchMap((result1: MyObservable1) => {
if (condition) {
return myObservable2;
} else {
return of(null);
}
})
).subscribe(myObservable1 | myObservable2) => {
Run Code Online (Sandbox Code Playgroud)
因此,如果条件为假,我只需要执行一个请求,如果条件为真,我必须将第一个请求链接到下一个请求,它们本质上是对服务器 api 的两个请求。
有没有更好的解决方案而不返回它null?
RxJs 中有条件运算符吗?
谢谢!
我用@ angular / cli-> ng new创建了一个新的Angular 8项目,添加了一个新的lazy模块,ng serve可以正常工作,但是ng build --prod会引发以下错误:
这是我的app.module.ts
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
这是我的app-routing.module.ts
const appRoutes: Routes = [
{
path: '',
redirectTo: 'dashboard',
pathMatch: 'full',
},
{
path: 'dashboard',
loadChildren: () => import(`./dashboard/dashboard.module`).then(m => m.DashboardModule),
}
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes)
],
exports: [
RouterModule
]
})
export class AppRoutingModule { }
Run Code Online (Sandbox Code Playgroud)
这是我的dashboard.module.ts
@NgModule({
imports: [
DashboardRoutingModule …Run Code Online (Sandbox Code Playgroud) 我随机收到错误:
失败:等待 Protractor 与页面同步时出错:“angularJS 可测试性和 Angular 可测试性都未定义。这可能是因为这是一个非角度页面,或者因为您的测试涉及客户端导航,这可能会干扰 Protractor 的引导。有关详细信息,请参阅https://github.com/angular/protractor/issues/2643 ”
跑步
$ ng e2e --webdriverUpdate=false --devServerTarget=
Run Code Online (Sandbox Code Playgroud)
在我的 spec.ts 文件中,我有以下 2 个测试,第一个总是有效,第二个随机失败并出现上述错误。
beforeEach(async () => {
myPage = new MyPage();
browser.get('my-page');
});
it('should work', async () => {
console.log('should work');
expect(true).toBeTruthy();
});
it('should display the title', async () => {
const title = await $('my-title-selector').getText();
expect(title).toEqual('My-Title');
});
Run Code Online (Sandbox Code Playgroud)
这是 MyPage 页面对象:
import { $, $$ } from 'protractor';
export class MyPage {
title = $('my-title-selector');
}
Run Code Online (Sandbox Code Playgroud)
这是我的 …
因为众所周知应该避免在 BehaviorSubject 上使用 getValue() 方法链接 我想知道读取和更新 BehaviorSubject 的最佳方法是什么。
在我的例子中,我有一个 BehaviorSubject 存储一个对象数组,当我单击一个按钮时,我应该将另一个对象推送到该数组并将新值发送给所有订阅者。
现在我正在做:
this.myBehaviorSubject.next([
...this.myBehaviorSubject.value,
{ new object }
])
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法?
谢谢!!
我正在使用Angular Material Dialog 组件,使用 mat-dialog-content 和 mat-dialog-actions 来显示带有动作按钮的页脚。
如果我设置对话框的高度(例如 80%),则对话框操作会奇怪地高于默认值。
我只是设置高度:80%
const dialogRef = this.dialog.open(DialogContentExampleDialog, {
height: '80%',
width: '520px'
});
Run Code Online (Sandbox Code Playgroud)
结果如下:
在我看来,这是一个问题:) 但你有什么看法?是否可以轻松修复它?
谢谢!
我正试图在我的笔记本上安装ROR(Debian Wheezy 64位).
首先我有这个问题(在这里输入链接描述),由第一个答案解决.
现在rails服务器启动了,但是在localhost:3000浏览器上我收到以下错误:
无法加载'active_record/connection_adapters/sqlite3_adapter'.确保config/database.yml中的适配器有效.如果您使用"mysql","mysql2","postgresql"或"sqlite3"以外的适配器,请将必要的适配器gem添加到Gemfile中.
我已经安装了ruby 2.0.0编译源代码,没有错误或错误.然后我安装了一些需要的库(sqlite3,libsqlite3-dev)......
这是我的GemFile:
'https://rubygems.org'
-# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
-# Use sqlite3 as the database for Active Record
gem 'sqlite3'
-# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
-# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
-# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
-# See https://github.com/sstephenson/execjs#readme for more supported runtimes
-# gem 'therubyracer', platforms: :ruby …Run Code Online (Sandbox Code Playgroud) 我不明白为什么即使我使用ChangeDetectionStrategy.OnPush和changeDetectorRef.detach()函数ngDoCheck一直被调用.我的应用程序中有数千个组件,如果从child2引发了一个事件(鼠标点击等),我想阻止child1的changeDetection.
这是一个掠夺者
如你所见,我有一个父组件
@Component({
selector: 'my-app',
template: `
<app-child1 test="test"></app-child1>
<app-child2 test="test"></app-child2> `,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent {
test = 'test';
constructor() { }
ngDoCheck() {
console.log("### ngDoCheck app component");
}
}
Run Code Online (Sandbox Code Playgroud)
和2个相同的孩子:
@Component({
selector: 'app-child1',
template: `<input type="text" [(ngModel)]="test" /><br/> `,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class Child1Component implements OnInit {
@Input()
test: string;
constructor(public cd: ChangeDetectorRef) { }
ngAfterViewInit() {
console.log("###### DETACH child 1");
this.cd.detach();
}
ngDoCheck() {
console.log("### ngDoCheck child 1");
}
}
Run Code Online (Sandbox Code Playgroud)
如果我开始输入child1的输入,则调用child2的ngDoCheck函数.
想想有成千上万的孩子,它真的很慢...... …
我正在开发 Angular 6 项目。
我的目标非常具体(Chrome 67),那么是否有任何提示可以排除其他目标浏览器所需的所有可能的polyfill?
谢谢!
我有一个联合类型项目,如下所示:
export interface A {
a: number
}
export interface B {
b: string
}
export type MyUnionType = A | B;
Run Code Online (Sandbox Code Playgroud)
我想根据属性 a 或 b 的存在来检查模板中 MyUnionType 类型的对象是否属于 A 类型或 B 类型。
我期望这样的事情应该有效:
<div *ngIf="'a' in item">
{{item.a}}
</div>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢!
angular ×7
rxjs ×2
arrays ×1
java ×1
json ×1
lazy-loading ×1
modal-dialog ×1
polyfills ×1
protractor ×1
sqlite ×1
switchmap ×1
templates ×1
tsconfig ×1
typescript ×1