小编A. *_*Lau的帖子

TypeScript类到JSON

我有一个类数组,类如下所示:

class Tag{
    select: string;
    search: string;
}
Run Code Online (Sandbox Code Playgroud)

我想将它转换为JSON,它可能看起来像[{select: "blah", search: "bleh"}, {...}, {...}].

这可能吗?因为从Angular 2教程中你可以使用相反的行:

.map((r: Response) => r.json().data as Hero[]);
Run Code Online (Sandbox Code Playgroud)

javascript json typescript

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

如何使用按钮添加更多输入字段 - Angular 2动态表单

所以我在这里使用了指南:https://angular.io/docs/ts/latest/cookbook/dynamic-form.html

我需要在现有字段中添加更多字段.我做了一些有用的东西,但它很笨重,当它击中它时它重置了形状.代码如下:

在dynamic-form.component.ts中:

add_textbox()
{
    this.questions.push(this.questionService.create_textbox({key: "test", label: "Test"}));
    console.log(this.questions);
    this.form = this.qcs.toFormGroup(this.questions);
}
Run Code Online (Sandbox Code Playgroud)

在question.service.ts

create_textbox({key, value, label = '', order = 1, type = "text", description = "", help = ""}: {key?: any, value?: any, label?: any, order?: any, type?: any, description?: any, help?: any})
{
    return new TextboxQuestion({
        key,
        label,
        value,
        order,
        description,
        type
    });
}
Run Code Online (Sandbox Code Playgroud)

我的按钮也在,dynamic-form.component.html但我希望它可以dynamic-form-question.component.ts代替.这可能吗?

forms angular2-forms angular2-formbuilder angular

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

mysql/mariadb - 创建表列索引不起作用

所以我正在尝试按如下方式创建表:

CREATE TABLE company
  (
    id INT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
    name TEXT UNIQUE NOT NULL,

    INDEX(name(20))
  );
Run Code Online (Sandbox Code Playgroud)

它给了我这个错误:

ERROR 1170 (42000): BLOB/TEXT column 'name' used in key specification without a key length
Run Code Online (Sandbox Code Playgroud)

我不确定为什么它不起作用,因为我遵循这里的指南:https://dev.mysql.com/doc/refman/5.5/en/column-indexes.html

mysql mariadb

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

git 从第一次提交中删除文件

所以这个问题不是这个问题:尽管它很相似,但从 Git 提交中删除文件。

我处于无法做到的情况:

git reset --soft HEAD~1
Run Code Online (Sandbox Code Playgroud)

因为我是第一次提交。

我想知道如何从我的提交中删除文件,因为我无法回溯。

git

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

包含Node.JS(vue)的文件

所以我想知道如何包含另一个JavaScript文件.很像PHP的include函数/关键字.我不是在寻找这个export功能,因为它只允许你使用其他文件中的变量.

我正在使用vue init webpack my-project.

这是我基本上拥有的(Vue):

mounted () {
    socket = io("http://localhost:8081")
    socket.connect()

    // ensure server has actually put us in a room
    socket.on("find game", () => {
        this.gameSearch = "finding"
    })
    ...
}
Run Code Online (Sandbox Code Playgroud)

所以基本上我有一大堆socket.on我想进入另一个文件.我想知道如何能够将它们包含在原样中以便它们可以像代码已经插入那样工作(就像PHP一样include)


它最终会是什么样子:

mounted () {
    <socket.js file>
}
Run Code Online (Sandbox Code Playgroud)

socket.js

socket = io("http://localhost:8081")
socket.connect()

// ensure server has actually put us in a room
socket.on("find game", () => {
    this.gameSearch = "finding"
})
...
Run Code Online (Sandbox Code Playgroud)

javascript node.js vue.js vuejs2

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

mongodb 从 facet 返回对象

是否可以让 facet 作为对象而不是数组返回?需要访问result[0].total而不是仅仅访问似乎有点违反直觉result.total

代码(使用猫鼬):

        Model
            .aggregate()
            .match({
                "name": { "$regex": name },
                "user_id": ObjectId(req.session.user.id),
                "_id": { "$nin": except }
            })
            .facet({
                "results": [
                    { "$skip": start },
                    { "$limit": finish },
                    {
                        "$project": {
                            "map_levels": 0,
                            "template": 0
                        }
                    }
                ],
                "total": [
                    { "$count": "total" },
                ]
            })
            .exec() 
Run Code Online (Sandbox Code Playgroud)

javascript mongoose mongodb

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

esm无法解析模块别名

所以我正在使用package esm和module-alias,但是esm似乎没有注册模块别名的路径。

这是我加载服务器文件的方式:

nodemon -r esm ./src/index.js 8081
Run Code Online (Sandbox Code Playgroud)

这是我index.js文件的顶部:

import "module-alias/register"
import "@/setup"
Run Code Online (Sandbox Code Playgroud)

import "@/setup"不起作用而起作用require("@/setup")。

javascript node.js npm

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

Linux命令行将pdf转换为excel

我正在寻找一个可以从命令行可靠地将 pdf 转换为 Excel 电子表格的工具(因为我想使用脚本来自动执行此操作)。

我需要能够正确转换 pdf 的工具,就像使用 Acrobat Pro 或类似程序一样。

linux pdf excel command-line

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

align-items:居中会使img消失

因此,使用网格时,当我没有align-items: center;img时,align-items: center;它可以正常显示,但是一旦添加,它就会突然消失。是什么导致此问题?

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 100px;
}

img {
  display: block;
  max-height: 100%;
  margin: 0 auto;
}

.align {
  align-items: center;
}
Run Code Online (Sandbox Code Playgroud)
<div class="grid">
  <div>
    <span>text</span>
  </div>
  <div>
    <img src="http://via.placeholder.com/650x1050" />
  </div>
</div>

<div class="grid align">
  <div>
    <span>text</span>
  </div>
  <div>
    <img src="http://via.placeholder.com/650x1050" />
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

这似乎是Chrome问题。它也不适用于Firefox上的img。

html css css3 css-grid

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

使用 await 在 try/catch 块中声明一个常量

所以我目前有这个:

var item_id
try {
    item_id =
        await
            (async function () {
               // code
            })();
} catch (error) {

}
Run Code Online (Sandbox Code Playgroud)

但我更喜欢item_id作为一个常量。鉴于该节点要求我处理承诺拒绝,将 await 值分配给 const 的最佳方法是什么

例如错误:

[0] (node:77118) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: details[Symbol.iterator] is not a function
[0] (node:77118) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Run Code Online (Sandbox Code Playgroud)

异步代码

await
    (async function () {
        const query = …
Run Code Online (Sandbox Code Playgroud)

javascript node.js

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