我希望控制台首先打印'1',但我不确定如何调用异步函数并等待其执行,然后再转到下一行代码.
const request = require('request');
async function getHtml()
{
await request('https://google.com/', function (error, response, body) {
console.log('1');
});
}
getHtml();
console.log('2');
Run Code Online (Sandbox Code Playgroud)
当然,我得到的输出是
2
1
Run Code Online (Sandbox Code Playgroud) 我一直试图在类似的问题中找到这个问题的答案,但我仍然不知道是什么导致了它。
我有一个多模块 maven 项目,我正在尝试运行mvn install或者mvn package我收到以下错误
[信息] 应用程序 ..................................... ..... 成功 [1.025 秒]
[信息] 模块数据 ..................................... FAILURE [ 0.952 s]
[INFO] module-app ...................................... 跳过
[ERROR] 无法执行目标 org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE:repackage (repackage) on project project-data: 执行目标 org.springframework.boot:spring-boot 的重新打包-maven-plugin:2.1.1.RELEASE:repackage failed: Unable to find main class -> [Help 1]
该project-app模块在 src 文件夹中有一个 java 类,而该project-data模块没有主类。
父 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<modules>
<module>project-data</module>
<module>project-app</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent …Run Code Online (Sandbox Code Playgroud) 是否可以隐藏inputprimeng日历中的字段,并仅显示图标?我不想将p-calendar元素更改为内联,而只是显示将弹出日历的图标。
组件.html
<div class="ui-g-12 ui-md-4">
<p-calendar class="foo-cal" appendTo="body" readonlyInput="true" dateFormat="yy/mm/dd" [(ngModel)]="date" [showIcon]="true"></p-calendar>
</div>
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法,但没有成功:
body .ui-calendar.ui-calendar-w-btn .ui-inputtext {
display: none !important;
}
p-calendar span input {
display: none !important;
}
Run Code Online (Sandbox Code Playgroud)
但是,使用浏览器中的开发工具,如果我将display: none;属性添加到元素,它将隐藏,仅留下图标。有什么想法可以让我在没有输入字段的情况下渲染 html 文件吗?
我正在尝试使用单个 p5.js 草图创建一个 React 应用程序。但是,包含 p5 草图的组件正在我的页面上复制。不知道为什么会这样呈现。
在这里您可以看到代码:https://stackblitz.com/edit/react-ts-kocwqw ?file=App.tsx,Sketch.tsx,index.tsx
以下是反应组件的定义:
应用程序.tsx
import React = require('react');
import Sketch from './Sketch';
function App() {
return (
<div className="App">
<Sketch />
</div>
);
}
export default App;
Run Code Online (Sandbox Code Playgroud)
草图.tsx
import React = require('react');
import { useEffect } from 'react';
import p5 from 'p5';
const Sketch = () => {
const p = (p5: any) => {
let radius: number;
p5.setup = () => {
p5.createCanvas(p5.windowWidth / 2, p5.windowHeight / 2);
p5.background(0);
radius = …Run Code Online (Sandbox Code Playgroud) 以下查询获取对象所需的所有键名称jsonb。基本上,从名为“objects”的列中获取包含“foo”的所有键名称。
SELECT keys
FROM (
SELECT jsonb_object_keys(objects) as keys
from table
) as testvalues
WHERE keys LIKE '%foo%';
Run Code Online (Sandbox Code Playgroud)
一旦获得键名称集,我想访问status该对象的字段,如下所示
SELECT objects->'hello_foo'->'status' FROM table
Run Code Online (Sandbox Code Playgroud)
但是,我仍然找不到一种方法来遍历第一个查询中的键名称集并动态访问该status字段。
最好的实施是什么?
<div class="form-group" [formGroup]="gGroup">
<label for="grouplabel">Group</label>
<select formControlName="groupControl" [(ngModel)]="groupobj" (ngModelChange)="onSelectGroup($event)" id="group" class="form-control">
<option>Select</option>
<option *ngFor="let group of groups" [selected]="current_group === group.name">{{group.name}}</option>
</select>
</div>
Run Code Online (Sandbox Code Playgroud)
如何在组件中将<select>字段的值设置为“ 动态选择 ”?
我看了看文档https://angular.io/api/forms/FormControlName#use-with-ngmodel,但仍然没有可以帮助我的示例。
尝试:
this.gGroup.get('groupControl').setValue('Select');
下面的代码给了我以下错误:
语法错误:await 仅在异步函数中有效
async function getLastTransaction()
{
paymentsApi.listPayments(locationId, opts).then(function(transactions)
{
if(transactions[transactions.length-1] === undefined)
return; //no new transaction yet
var last_transaction_id = transactions[transactions.length-1].id;
var last_transaction_in_queue;
try {
last_transaction_in_queue = JSON.parse(order_queue[0]).order_id;
} catch (e) {
last_transaction_in_queue = order_queue[0].order_id;
}
//check if latest transaction is the same as lastest transaction in queue
if(last_transaction_id !== last_transaction_in_queue) {
console.log(`new payment...`);
var obj = await createTransactionObject(transactions[transactions.length-1], () => {
order_queue.unshift(obj);
console.log('new added', order_queue);
});
}
Run Code Online (Sandbox Code Playgroud)
我不明白这个错误,因为我使用await的是相同的功能,createTransactionObject()但在另一段代码中。
例如,在下面的代码中,我没有收到错误消息,但我await之前还在使用createTransactionObject()
async function …Run Code Online (Sandbox Code Playgroud) 这是我的类定义的样子:
timeLeft: Number;
constructor() {
this.timeLeft = 60;
}
start() {
console.log(typeof(this.timeLeft)); // prints out 'number'
setInterval(() => {
this.timeLeft--; // error TS2356 occurs here
console.log(this.timeLeft);
}, 1000);
}
ngOnInit() {}
Run Code Online (Sandbox Code Playgroud)
安慰:
错误 TS2356:算术操作数的类型必须为“any”、“number”或枚举类型。
javascript ×4
async-await ×2
node.js ×2
angular ×1
angular6 ×1
css ×1
java ×1
jsonb ×1
maven ×1
multi-module ×1
p5.js ×1
postgresql ×1
primeng ×1
promise ×1
react-hooks ×1
reactjs ×1
request ×1
setinterval ×1
spring ×1
sql ×1
typescript ×1