我试图用Promise编写这段代码.但我不知道如何在Promise和循环中写承诺.我试着像这样想,但insertBook函数变得异步.如何同步获取bookId?
update: function(items, quotationId) {
return new Promise(function(resolve, reject) {
knex.transaction(function (t) {
Promise.bind(result).then(function() {
return process?
}).then(function() {
return process?
}).then(function() {
var promises = items.map(function (item) {
var people = _.pick(item, 'familyName', 'firstNumber', 'tel');
if (item.type === 'book') {
var book = _.pick(item, 'name', 'bookNumber', 'author');
var bookId = insertBook(t, book);
var values = _.merge({}, people, {quotation: quotationId}, {book: bookId});
} else {
var values = _.merge({}, people, {quotation: quotationId});
}
return AModel.validateFor(values);
});
return Promise.all(promises);
}).then(function(items) { …Run Code Online (Sandbox Code Playgroud) 默认情况下,当esc按下按钮时,对话框关闭。但是,我不希望这种预期的行为。
我想做的是防止在esc按下按钮时关闭窗口,但仍然允许在背景上单击以关闭对话框。如何才能做到这一点?
我已经尝试过这样的事情。但是,它不起作用:
openEditDialog() {
const dialogRef = this.dialog.open(EditPlaceDialogComponent, {
width: '90%',
height: '720px'
});
dialogRef.keydownEvents().subscribe(e => {
if (e.keyCode === 27) {
e.preventDefault();
dialogRef.disableClose = false;
}
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
});
}
Run Code Online (Sandbox Code Playgroud) 首先,在ngOnInit()中设置表设置数据,并将其设置为settingA变量。
此设置变量绑定到html中的设置。
并且我想使用settingA在子组件中制作表格。
但是子组件ngOnInit在父组件的ngOnInit完成之前被调用。
因此在子组件中设置变量是不确定的。
请给我建议。
这是父组件[grid-serialize.component.ts]
@Component({
selector: 'grid-serialize',
templateUrl: './grid-serialize.component.html',
styles: []
})
export class GridSerializeComponent implements OnInit, OnChanges {
tableSetting: TableSetting;
settingA: TableSetting;
rows: Bom[] = [];
cols: ColumnSettings[] = [];
userId: string;
url: string;
area: string;
constructor(
private router: Router,
private tableService: TableService,
private localStorageService: GridService
) {}
ngOnInit(): void {
this.userId = 'user01';
this.url = this.router.url;
const areaA = 'upper';
const rowDataPathA = 'aaa/aaa/data.json';
const columnDataPathA = 'bbb/bbb/column.json';
const reorderableColumnsA = false;
const resizableColumnsA = …Run Code Online (Sandbox Code Playgroud) 当我将ag-grid与tooltipField属性一起使用时,我陷入了困境。我想在ag-grid的每一行中实现工具提示。
代码如下。此代码无效。
{headerName: 'vital',
field: 'indicator',
tooltipField: 'indicator',
cellRenderer: (p:any) => {
return '<div align="center"><button class="btn btn-sm btn-primary" tooltip="'
+ this.translateService.instant(p.value)
+ '"></button></div>';
}},
Run Code Online (Sandbox Code Playgroud) 我想在单击按钮时更改材质垫-迷你晶圆厂按钮的颜色。
我的尝试如下。但是不起作用。
<button mat-mini-fab color="primary" #btn>Btn</button>
@ViewChild('btn') btn: ElementRef;
clicked() {
this.btn.nativeElement.style.backgroundColor = '#5789D8';
this.btn.nativeElement.style.color = '#FFFFFF';
}
Run Code Online (Sandbox Code Playgroud)