小编dae*_*dog的帖子

Prisma 数据建模有很多并且属于

我有一个由根类别和子类别组成的棱镜数据模型。一个类别有许多子类别,一个子类别属于一个类别。我的模型看起来像这样:

  type Category {
    id: ID! @unique
    createdAt: DateTime!
    updatedAt: DateTime!
    name: String!
    subCategories: [SubCategory!]! @relation(name: "Subcategories")
  }

  type SubCategory {
    id: ID! @unique
    createdAt: DateTime!
    updatedAt: DateTime!
    name: String!
    category: Category! @relation(name: "ParentCategory")

    cards: [Card!]! @relation(name: "SubCategoryCards") #Category @relation(name: "CardCategory")
  }
Run Code Online (Sandbox Code Playgroud)

现在当我去创建一个新的子类别并通过

mutation {
    createSubCategory(data:{
        name:"This is a test"
        category:{
            connect:{
                id:"cjp4tyy8z01a6093756xxb04i"
            }
        }
    }){
        id
        category{
            name
            id
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这似乎工作正常。下面我查询子类别及其父类别,并得到我期望的结果。

{
    subCategories{
        id
        name
        category{
            id
            name
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试查询一个类别并获取它的所有子类别时,我得到了一个空数组:

{
    categories{
        id
        name
        subCategories{ …
Run Code Online (Sandbox Code Playgroud)

plumatic-schema graphql prisma

3
推荐指数
1
解决办法
721
查看次数

如何删除构造函数中重复的代码?

我有以下代码;

abstract class Animal{

    public String name;
    public int legCount;

    //If has no leg count
    public Animal(String name){
        this.name = name;
        this.legCount = 4;  //Default leg count is 4

        System.out.println("Created animal: " + name);
    }

    //If has a leg count
    public Animal(String name, int legCount){
        this.name = name;
        this.legCount = legCount;

        System.out.println("Created animal: " + name);
    }}
Run Code Online (Sandbox Code Playgroud)

我重复了System.out.println("Created animal:"+ name); 两次.有没有办法删除这个重复的代码,所以它只运行一次?拥有多个构造函数可能会让这有点痛苦.

java constructor object

3
推荐指数
2
解决办法
139
查看次数

如何使用Flutter StreamBuilder重试错误?

我有一个StreamBuilder对象来呈现FireStore集合中的列表:

Widget build(BuildContext context) {
    return StreamBuilder<QuerySnapshot>(
    stream: Firestore.instance.collection('posts').snapshots(),
    builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (snapshot.hasError) return new Text('Error: ${snapshot.error}');
        switch (snapshot.connectionState) {
            default:
            return new ListView(
            children:
            snapshot.data.documents.map((DocumentSnapshot document) {
                return Post(document: document);
            }).toList());
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试使其,如果snapshot.hasError,则StreamBuilder会再次尝试。我怎样才能做到这一点?

flutter

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

使用 axios 将 vue.js 数据对象发送到后端

我需要通过 axios 将 Vue 实例的完整数据对象发送到后端。这是我的代码。

var vm = new Vue({
    el: '#el',
    delimiters: ["[[", "]]"],
    data: {
        brand: 0,
        model: 0,
        country: "europe",
    },
    created: function () {
    },
    updated: function () {
        axios.post('http://localhost:81/lnt/public/member/car_result', {data: this.data})
            .then(function (response) {

        });
    }
});
Run Code Online (Sandbox Code Playgroud)

当我console.log(this.data);得到一个未定义的输出 当我尝试

axios.post('http://localhost:81/lnt/public/member/car_result', {brand: this.brand})
Run Code Online (Sandbox Code Playgroud)

我可以发送品牌但需要一次发送整个数据阵列

vue.js axios

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

如何等待多个 fs.readFile 调用?

我的目标是从两个文件中读取数据并比较数据。我的输入文件是result3.json和result4.json。这些文件中的数据是逗号分隔的。

结果3.json

[
  "temp1.txt",
  "temp2.txt",
]
Run Code Online (Sandbox Code Playgroud)

节点:

function readFromFile(file) {
    var fileNames = [];
    //setTimeout(function() {
        fs.readFile(file,function(err, data){
            if (err) {
                return console.log(err);
            }
            var temp = JSON.parse(data.toString().split(","));
            // console.log(temp.length);
            for (let index = 0; index < temp.length; index++) {
                //console.log(temp[index]);
                fileNames.push(temp[index]);
                //console.log(fileNames[index]);
            }
            Done(); // to block the async call
        });
        //},3000);
    //console.log(fileNames.length);
    return fileNames;
}

var baseListOfFiles = readFromFile('./output/result3.json'); // Assume this is the base file
var currentListOfFiles = readFromFile('./output/result4.json'); // Assume this is the current file

function …
Run Code Online (Sandbox Code Playgroud)

javascript node.js

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

对数字进行排序,使偶数提前

我有20个随机数的数组(从-10到10),我需要对它们进行排序.偶数必须在数组前面.比如让arr = [-2,3,6,-12,9,2,-4,-11,-8]必须变成arr = [ - 12,-8,-2,2,4,6,-11 ,3,9]这是我的代码:

let array = Array(20).fill().map(() => Math.round(Math.random() * 20) - 10);

console.log(array);

function moveEvenToFront(array){
    let temp=0;
    let a=0;
    for(let i=0;i<array.length;i++){

        if(array[i] % 2 == 0){

            for (let j=i; j>a; j-- ){

                temp = array[j-1];

                array[j-1] = array[j];

                array[j] = temp;

            }
            a++;
        }

    }
    return array;
}

moveEvenToFront(array);
Run Code Online (Sandbox Code Playgroud)

我试过这个功能,但它不起作用.

javascript arrays

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

木偶不关闭浏览器

我在express / node / ubuntu上运行puppeteer,如下所示:

var puppeteer = require('puppeteer');
var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
    (async () => {
        headless = true;
        const browser = await puppeteer.launch({headless: true, args:['--no-sandbox']});
        const page = await browser.newPage();
        url = req.query.url;
        await page.goto(url);
        let bodyHTML = await page.evaluate(() => document.body.innerHTML);
        res.send(bodyHTML)
        await browser.close();
    })();
});
Run Code Online (Sandbox Code Playgroud)

多次运行此脚本会留下数百个僵尸:

$ pgrep chrome | wc -l
133
Run Code Online (Sandbox Code Playgroud)

哪个阻塞了srv,

我该如何解决?

kill从Express JS脚本运行可以解决吗?

除了木偶戏和无头镀铬之外,还有没有更好的方法来获得相同的结果?

puppeteer

2
推荐指数
5
解决办法
4450
查看次数

cdk-drop 不是已知元素

我正在使用 Angular 7“拖放”的新功能,我遵循了官方文档上的所有步骤:https : //material.angular.io/cdk/drag-drop/overview

但我收到此错误:**

未捕获的错误:模板解析错误:'cdk-drop' 不是已知元素: 1. 如果 'cdk-drop' 是一个 Angular 组件,则验证它是否是该模块的一部分。2. 如果'cdk-drop' 是一个Web 组件,则将'CUSTOM_ELEMENTS_SCHEMA' 添加到该组件的'@NgModule.schemas' 以抑制此消息。

**

这是我的 app.component.html 代码:

<cdk-drop cdkDropList class="example-list" (cdkDropListDropped)="drop($event)">
  <div class="example-box" *ngFor="let movie of movies" cdkDrag>{{movie}} 
  </div>
</cdk-drop>
Run Code Online (Sandbox Code Playgroud)

这是我的 app.component.ts 代码:

import { Component } from '@angular/core';
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    movies = [
    'Episode I - The Phantom Menace',
    'Episode II - Attack of the …
Run Code Online (Sandbox Code Playgroud)

javascript drag-and-drop drag angular angular7

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

如何在不同的端口上运行多个快递服务器?

从过去的一周学习节点,并掌握节点和表达。但是现在我面临一个问题。我试图在不同的端口上运行多个Express服务器,并希望它们在10秒后返回响应。运行该程序后,服务器可以正常运行,但是当我单击http:// localhost:3000或任何服务器的URL时,请注意以下几点:
-在客户端,我在10秒钟后从所有服务器获得了正确的响应
-服务器正在进入无限循环并在10秒钟的延迟后连续打印“返回数据...”

我尝试使用一个函数,使用js文件导出服务器,并使用另一个类导入服务器并在for循环内调用。但是服务器在延迟10秒后会不断打印“正在返回数据...”。下面是我的代码:

var express = require('express');

const data = '{"key":"value"}';
const server = function (port) {
    let app = express();
    app.get('/', (req, res) => {
        setInterval(function () {
            console.log('returning data...')
            res.end(data);
        }, 10000); //want a delay of 10 secs before server sends a response
    })
    app.listen(port, () => console.log("Server listening at http://%s:%s",
    "localhost", port))
}

console.log('\nStarting servers.......')
for (var i = 0; i < 5; i++) {
    server(3000 + i)
}
Run Code Online (Sandbox Code Playgroud)

javascript node.js express

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

当单个单片文件没有时,C++ Struct Constructor与参数分隔成标题和实现文件失败

我已经多次看到这个问题,但基本答案似乎是多次包含头文件.在我的情况下,这不是问题,我不知道是什么.

我有一个基本的c ++文件似乎在这里正常工作:

// Filename : t1.cpp
#include <stdio.h>

struct T1{
    int result;

    T1(int var1, int var2) {
        result = var1 * var2;
    }
};

void main(void){
    T1 t(2, 3);
    printf("%d\n", t.result);
}
Run Code Online (Sandbox Code Playgroud)

编译并运行时,会产生答案6.大.现在,当我将这段代码分成两个文件,一个.cpp和一个.h时,我得到错误(错误C2011:'T1':'struct'类型重定义).这两个不同的文件是这样的:

//Filename : test1.h
#ifndef TEST_H
#define TEST_H

struct T1{
    int result;

    T1(int var1, int var2);
};
#endif

//Filename : test1.cpp
#include "test1.h"

struct T1{
    int result;

    T1(int var1, int var2) {
        result = var1 * var2;
    }
};
Run Code Online (Sandbox Code Playgroud)

我曾经尝试过使用#pragma一次,以及使用class而不是struct,但这并不重要.这里有些根本错误.我不明白它为什么在独立文件中工作,但在分成标题和实现版本时却不行.我需要对标头和实现文件做些什么?

c++

0
推荐指数
1
解决办法
43
查看次数

如何在 C++ 中重新利用基类的字段?

我想设计一个节点类,然后我可以将其用于各种类型的树,但是当我尝试考虑如何以不创建不必要的字段的方式进行时,我遇到了复杂的问题。例如,我有以下课程:

class Node {
protected:
    Node *left;
    Node *right;
}
Run Code Online (Sandbox Code Playgroud)

此类将具有处理获取和设置节点左右连接的方法。但是,我还将有下一堂课:

class BinaryNode : public Node { 
protected:
    BinaryNode *left_child;
    BinaryNode *right_child;
    BinaryNode *parent;
}
Run Code Online (Sandbox Code Playgroud)

除了新的父连接,左右子节点可以使用基类的左右连接来描述,但我不能使用它们,因为它们不是二进制节点。有没有合适的方法来重新调整它们的用途,使其按照我想要的方式行事?

我还想到这可能不值得付出努力,无论如何我应该创建新字段,这样我就不会被迫拖拽有时不直观的名称和可疑的铸造。我欢迎对这个想法发表意见。

c++ inheritance

0
推荐指数
1
解决办法
54
查看次数

不在字符串中使用空终止会有什么影响?

以下面的代码为例:

int main(){
    char string[] = { 'h' , 'e', 'l', 'l', 'o' };
    printf(string);
    printf("\n%d", strlen(string));
}
Run Code Online (Sandbox Code Playgroud)

输出将是:

hello
6
Run Code Online (Sandbox Code Playgroud)

因此,从一开始我就可以看到strlen价值偏差为1,但如果我们考虑它,它似乎并不是一个障碍.

什么时候不终止字符串会产生问题?

c string char

-5
推荐指数
1
解决办法
155
查看次数