小编gre*_*ard的帖子

Angular 9:如何重新渲染组件

我有一个父组件和一个子组件。如果子组件在内部更新其值,我无法从父组件更新回值。

请参阅此 Stackblitz 中的示例:https ://stackblitz.com/edit/angular-ivy-tynepp 。当子组件失去焦点时,我会触发一个事件,父组件会重置子组件的值。但我认为,因为父级的“this.value”没有改变,所以更新不会触发子级的检测更改。

我该如何解决这个困境?

components angular angular-changedetection

7
推荐指数
1
解决办法
2万
查看次数

任务有向无环图的并行执行

我有一个任务清单[Task-A,Task-B,Task-C,Task-D, ...]
一项任务可以选择依赖于其他任务。

例如:
A 可以依赖于 3 个任务:B、C 和 D
B 可以依赖于 2 个任务:C 和 E

它基本上是一个有向无环图,并且任务的执行应该仅在执行相关任务之后发生。

现在可能会发生这样的情况:在任何时间点,都有多个任务可供执行。在这种情况下,我们可以并行运行它们。

关于如何在具有尽可能多的并行性的同时实现这样的执行有什么想法吗?

class Task{
     private String name;
     private List<Task> dependentTasks;
     
     public void run(){
     // business logic
     }
}
Run Code Online (Sandbox Code Playgroud)

java algorithm concurrency multithreading directed-acyclic-graphs

7
推荐指数
2
解决办法
3651
查看次数

加载 web 视图时出错:错误:无法注册服务工作者:类型错误:无法为作用域注册服务工作者

当我将 VSCode 更新到 v1.56.2 并打开 webview 时,我收到以下消息:

加载 webview 时出错:错误:无法注册服务工作者:TypeError:无法使用脚本('vscode-webview:/ /867f875b-c5a3-4504-8de2-2e8614bdc0f8/service-worker.js?platform=electron&id=867f875b-c5a3-4504-8de2-2e8614bdc0f8&vscode-resource-origin27F%204b3-resource-origin27f204b3-origin27f28dc885f28dc85c85f28dc885f2f28dc85c85f285c87f285c87f285c87f285c87f2885f2885c887f2f885c875b-c5a3-3 .vscode-webview-test.com'):ServiceWorker 无法启动。

我该如何解决这个问题?

visual-studio-code

7
推荐指数
10
解决办法
4389
查看次数

将十六进制写入文件

我有一个程序可以读取hex文件的 ,修改它,并将修改后的十六进制存储在std::string.

例如,我将如何将其写入文件

std::string wut="b6306edf953a6ac8d17d70bda3e93f2a3816eac333d1ac78";
Run Code Online (Sandbox Code Playgroud)

并获得它的价值

.0n..:j..}p...?*8...3..x
Run Code Online (Sandbox Code Playgroud)

在输出的文件中?

我不想使用sprintf,但我想如果有必要,我会做我必须做的。

c++ string hex file

6
推荐指数
1
解决办法
8122
查看次数

给定一个字符串,只在一次扫描中找到它的第一个非重复字符

给定一个字符串,找到其中的第一个非重复字符.例如,如果输入字符串是"GeeksforGeeks",则输出应为"f".

我们可以使用字符串字符作为索引并构建计数数组.以下是算法.

1)从左到右扫描字符串并构造计数数组或HashMap.
2)再次,从左到右扫描字符串并检查每个字符的计数,如果找到一个计数为1的元素,则将其返回.

以上算法来自GeeksForGeeks

但它需要两次扫描一个数组.我想在一次扫描中找到第一个非重复字符.我实现上面的算法.请在Ideone上查看

import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Neelabh
 */
public class FirstNonRepeatedCharacter {
    public static void main(String [] args){
        Scanner scan=new Scanner(System.in);
        String string=scan.next();
        int len=string.length();
        HashMap<Character, Integer> hashMap=new HashMap<Character, Integer>();
        //First Scan
        for(int i = 0; i <len;i++){
            char currentCharacter=string.charAt(i);
            if(!hashMap.containsKey(currentCharacter)){
                hashMap.put(currentCharacter, 1);
            }
            else{
                hashMap.put(currentCharacter, hashMap.get(currentCharacter)+1);
            }
        }
        // Second Scan
        boolean flag=false;
        char firstNonRepeatingChar = 0;
        for(int i=0;i<len;i++){
                char c=string.charAt(i);
                if(hashMap.get(c)==1){
                    flag=true;
                    firstNonRepeatingChar=c;
                    break;
                }
        }
        if(flag==true) …
Run Code Online (Sandbox Code Playgroud)

algorithm data-structures

6
推荐指数
2
解决办法
2万
查看次数

为什么(lt,gt)和(le,ge)反射而不是(lt,ge)和(le,gt)?

基本自定义中,python docs说明了比较方法:

[没有这些方法的交换参数版本]; 相反,__lt__()__gt__()彼此的思考,__le__()__ge__()在对方的反映,__eq__()__ne__()有自己的思考.

我会用更少的惊讶__lt__()__ge__()是彼此的反射(,以及__le__()__gt__()).

虽然文档也说明:

......比较运营商之间没有其他隐含关系,例如,事实(x<y or x==y)并非暗示x<=y,

什么,如果有的话,是或将是选择的反射关系的理由?

python

6
推荐指数
1
解决办法
713
查看次数

使用 NestJS 和类验证器创建标头自定义验证

我一直在努力使用类验证器和 NestJS 验证以及尝试验证标头内容来验证请求。
我的基本接口都可以工作,但现在我尝试以相同的方式比较一些标头字段数据。

我有一个关于自定义装饰器的问题来尝试处理标头,但该问题的解决方案将返回一个标头。我希望能够处理所有这些,类似于处理所有 body() 数据的方式。

我需要能够创建一个自定义装饰器来提取标头字段,并能够将它们传递到类验证器 DTO 中。

例如,我想验证三个标头字段,例如:

User-Agent = 'Our Client Apps'
Content-Type = 'application/json'
traceabilityId = uuid
Run Code Online (Sandbox Code Playgroud)

还有更多的领域,但如果我能做到这一点,那么我就可以推断出其余的领域。我有一个简单的控制器示例:

@Controller(/rest/package)
export class PackageController {

    constructor(
        private PackageData_:PackageService
    )
    { }

    ...

    @Post('inquiry')
    @HttpCode(HttpStatus.OK)        // Not creating data, but need body, so return 200 OK
    async StatusInquiry(
        @RequestHeader() HeaderInfo:HeadersDTO,     // This should be the Headers validation using the decorator from the question above.
Run Code Online (Sandbox Code Playgroud)

我正在尝试验证请求的标头是否包含一些特定数据,并且我正在使用 NestJS。我找到了这个信息。虽然这就是我想要做的,而且看起来很正确,但 ClassType 引用不存在,而且我不确定该使用什么。

从例子来看,装饰器指的是。

请求头.decorator.ts

export interface iError { …
Run Code Online (Sandbox Code Playgroud)

typescript class-validator nestjs

6
推荐指数
1
解决办法
1万
查看次数

如何使用带有 Spring-Boot JPA 和 Maven 的 Liquibase 来管理来自 JPA 实体的迁移

我一直在尝试使用liquibase来管理 Spring JPA 项目上的迁移,就像 Python/Django 使用makemigrations. Liquibase文档非常混乱,我尝试遵循我在网上找到的一些 SA 答案和教程,但无济于事。

这是我想要做的:

  1. 通过 JPA 注释类定义实体。
  2. 生成迁移以反映 MySQL 数据库上的这些实体。
  3. 在数据库上应用所述迁移。(最初为空)

到目前为止,我能够生成一个“差异”更改日志文件,并以某种方式设法让 liquibase在空数据库上创建databasechangelogdatabasechangeloglock表。但是,我无法master.xml使用差异更新文件或将差异应用于数据库。

到目前为止,这是我的配置(基本的 spring-jpa 项目,只有一个用于测试的实体):

Pom.xml(缩写)

<project>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.3</version>
        <relativePath/>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <groupId>my-group</groupId>
    <artifactId>web</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>15</maven.compiler.source>
        <maven.compiler.target>15</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <version>4.3.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins> …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa spring-boot liquibase-hibernate

6
推荐指数
0
解决办法
772
查看次数

为我的第一个 Angular 应用程序运行“ng serve”时出错

消息&跟踪:

Generating browser application bundles (phase: building)...(node:5312) UnhandledPromiseRejectionWarning: TypeError: MessagePort was found in message but not listed in transferList
    at new Worker (internal/worker.js:170:17)
    at SassWorkerImplementation.createWorker (C:\Users\shail\iacademiaApp1\node_modules\@angular-devkit\build-angular\src\sass\sass-service.js:96:24)
    at SassWorkerImplementation.render (C:\Users\shail\iacademiaApp1\node_modules\@angular-devkit\build-angular\src\sass\sass-service.js:62:40)
    at Object.loader (C:\Users\shail\iacademiaApp1\node_modules\sass-loader\dist\index.js:46:3)
(node:5312) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection …
Run Code Online (Sandbox Code Playgroud)

node.js angular-cli angular

6
推荐指数
1
解决办法
1572
查看次数

在 TypeORM 中使用外键查找行

User我有一个从到 的OneToMany 关系Message

当我使用消息插入注册用户时,它将用户添加到表中User,并将消息添加到Message表中并userId指向用户的 id。

这是使用以下设置自动完成的。

User实体:

@Entity()
export class User {
  @PrimaryGeneratedColumn() 
  id: number;

  @Column()
  name: string;

  @Column()
  email: string;

  @JoinTable()
  @OneToMany((type) => Message, (message) => message.user, {
    cascade: true,
  })
  messages: Message[];
}
Run Code Online (Sandbox Code Playgroud)

Message实体:

@Entity()
export class Message {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  text: string;
  @ManyToOne((type) => User, (user) => user.messages, { eager: true })
  user: User[];
}
Run Code Online (Sandbox Code Playgroud)

如果我想通过以下方式查找来自用户的所有消息userId

const existing_msgs = await this.messageRepository.find({
    where: …
Run Code Online (Sandbox Code Playgroud)

postgresql typeorm nestjs

6
推荐指数
1
解决办法
8302
查看次数