小编Dam*_*mon的帖子

如何使用 Nestjs 验证枚举值数组

我觉得这个线程这个线程的组合就是我需要实现的,我很难将它们放在一起。

我有一个包含enum.

使用 Postman,我正在发送一个PurchasableTypeofFOO并期望收到某种错误。看完上面的链接,感觉这个过程还是挺复杂的;这让我觉得我完全没有抓住要点。

如何使用验证管道来确保仅purchasable-type.enum.ts允许使用中的值?

感谢您的任何建议!

// create-order.dto.ts

import { IsEmail, IsNotEmpty, IsEnum } from 'class-validator';
import { PurchasableType } from '../enum/purchaseable-type.enum';

export class CreateOrderDto {
  @IsNotEmpty()
  readonly userId: string;

  @IsNotEmpty()
  readonly locationId: string;

  @IsNotEmpty()
  @IsEnum(PurchasableType)
  readonly purchasableType: PurchasableType;

  @IsNotEmpty()
  @IsEmail()
  readonly email: string;
}
Run Code Online (Sandbox Code Playgroud)
// purchasable-type.enum.ts

export enum PurchasableType {
  CLINIC = 'CLINIC',
  EVENT = 'EVENT',
  LESSON = 'LESSON',
  RESERVATION = 'RESERVATION',
  TEAM = 'TEAM',
}

Run Code Online (Sandbox Code Playgroud)

编辑 …

dto nestjs

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

如何使用Laravel Collective在表单标签中包含html?

通过这个SO线程阅读我已经读过我可以创建一个新的宏来创建自定义表单输入.

我对Laravel开发来说是一个全新的(大惊喜),对于这么小的事情来说似乎有点过分.是否有一种"更简单"的方式来做这样的事情:

刀片模板

{!!Form::label('firstName', 'First Name<sup>*</sup>') !!}
{!! Form::text('firstName', null, ['class'=>'required']) !!} 
Run Code Online (Sandbox Code Playgroud)

HTML

<label for="firstName">First Name*</label>
<input type="text" name="firstName" class="required">
Run Code Online (Sandbox Code Playgroud)

或者,这是一个我只是编写html,然后使用表单服务来创建输入的情况?

感谢您的耐心和洞察力.

laravel-5.2 laravelcollective

11
推荐指数
2
解决办法
6981
查看次数

NestJS EntityMetadataNotFoundError:找不到“存储库”的元数据

我知道有很多关于这个主题的帖子。我真的很难理解我到底想做什么来解决这个问题。使用 Postman,当我尝试命中路线时,出现以下错误:

ERROR [ExceptionsHandler] No metadata for "OrganizationsRepository" was found.
EntityMetadataNotFoundError: No metadata for "OrganizationsRepository" was found.
Run Code Online (Sandbox Code Playgroud)

这是我的代码的样子

// app.module.ts

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'postgres',
      host: 'localhost',
      port: 5432,
      database: 'my-database',
      username: 'postgres',
      password: 'password',
      autoLoadEntities: true,
      synchronize: true,
    }),
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    OrganizationsModule,
  ],
  controllers: [],
  providers: [],
  exports: [],
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)
// organizations.repository.ts

@EntityRepository(Organization). // this is showing as deprecated
export class OrganizationsRepository extends Repository<Organization> {
...
}
Run Code Online (Sandbox Code Playgroud)
// organization.entity.ts

@Entity({ name: 'organizations' …
Run Code Online (Sandbox Code Playgroud)

typescript typeorm nestjs

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

使用Form :: open()时,为什么我的CSRF令牌为空?

刚刚开始,所以请原谅我.我对CodeIgniter有扎实的把握,所以我理解发生了什么.但是,我在创建表单时注意到我的CSRF令牌是空的.我正在通过laracasts视频来了解Laravel工作流程.

myfile.blade.php

 {!! Form::open((array('action' => 'MyController@method'))) !!}
    ...
 {{!! Form::close() !!}}
Run Code Online (Sandbox Code Playgroud)

这是我查看源代码时得到的内容:

<form method="POST" action="http://mysite.dev/route" accept-charset="UTF-8">
<input name="_token" type="hidden">
</form>
Run Code Online (Sandbox Code Playgroud)

我查看了配置目录,但没有看到必须启用csrf.在我需要更新的地方是否有其他设置?

谢谢你的建议.

编辑

甚至这给了我一个空的隐藏输入字段:

{{ Form::token() }}  // <input name="_token" type="hidden">
Run Code Online (Sandbox Code Playgroud)

编辑

这是我的控制器的样子:

//use Illuminate\Http\Request;
use Request;
use App\Article;
use App\Http\Requests;
use App\Http\Controllers\Controller;


public function store(Request $request)
{
    $input = Request::all();

    return $input;
}
Run Code Online (Sandbox Code Playgroud)

所以我更新的表单标签如下所示:

{!! Form::open((array('action' => 'ArticleController@store'))) !!}
...
Run Code Online (Sandbox Code Playgroud)

当我提交时,我可以看到json响应 - 令牌显然是空的.

{"_token":"","title":"test","body":"test"}
Run Code Online (Sandbox Code Playgroud)

csrf laravel

8
推荐指数
1
解决办法
9135
查看次数

如何更改每周反应日期选择器天数的格式?

我正在使用React Datepicker,一切都很好。

而不是在一周中的几天使用“Su”“Mo”“Tu”等,我想使用这样的东西:

"Sun" "Mon" "Tue" 
Run Code Online (Sandbox Code Playgroud)

我正在通过 css 完成此操作:

.react-datepicker__day-name {
    ...
    &:first-child {
        &:after {
            visibility: visible;
            position: relative;
            left: -0.5rem;
            text-align: center;
            content: "Sun";
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

它似乎有效,但似乎也很“hacky”。是否有我在某处缺少的配置选项可以指定我想使用的格式?

感谢您的任何建议!

编辑

这是我(尝试)将 传递dateFormat给我的组件的方式:

应用程序.js

this.state = {
    startDate: new Date(),
    dateFormat: 'ddd'
};


...

render() {
    ...
     <ReservationCalendar
         dateFormat={ this.state.dateFormat }
         startDate={ this.state.startDate  }
     />
}
Run Code Online (Sandbox Code Playgroud)

预订日历.js

const ReservationCalendar = ({dateFormat, startDate}) => (
    <Calendar
        dateFormat={ dateFormat }
        startDate={ startDate }/>
);

export default ReservationCalendar; …
Run Code Online (Sandbox Code Playgroud)

reactjs react-datepicker

8
推荐指数
4
解决办法
6196
查看次数

正则表达式 - “没有可重复的”

这是我认为给我带来麻烦的正则表达式:

JavaScript:

theregex = /\$?\{(\d+)\}/g;
Run Code Online (Sandbox Code Playgroud)

输出如下:

Uncaught SyntaxError: Invalid regular expression: /$?\{(\d+)\}/: Nothing to repeat.
Run Code Online (Sandbox Code Playgroud)

我读过有关需要更多反斜杠来转义特殊字符的内容 - 但这会改变模式吗?

我正在使用regex101来帮助 - 它告诉我上面的正则表达式是有效的。显然有些东西认为它不是,而且我对正则表达式还不够熟悉,无法看到它。

编辑: 这是整个代码块。

JavaScript:

foo: function(element, rule) {
    var message = this.defaultMessage(element, rule.method),
       theregex = /\$?\{(\d+)\}/g;

       if (typeof message === "function") {
           message = message.call(this, rule.parameters, element);
       } else if (theregex.test(message)) {
           message = $.validator.format(message.replace(theregex, "{$1}"), rule.parameters);
       }
       this.errorList.push({
           message: message,
           element: element
        });
        this.errorMap[element.name] = message;
        this.submitted[element.name] = message;
        }
...
Run Code Online (Sandbox Code Playgroud)

javascript regex

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

使用Bootstrap从modal将数据传递到父窗口

作为一个例子,我有一个页面,加载时,列出所有员工.页面上有一个按钮,单击该按钮时,使用表单初始化(引导程序)模态.我填写表单,然后单击"提交".如果插入成功,我将json对象作为响应返回,这样我就可以将新创建​​的员工添加到列表中 - 这是模态的后面 - 没有页面刷新.

一切都很好.我收回了json - 我准备将数据发送回父窗口了.我知道这会有点棘手,但这篇SO帖子给了我希望.

jQuery的

Employee.createEmployee(function (response) {
    $(window.opener.document).find('#mytable').html($.parseJSON(response));
});
Run Code Online (Sandbox Code Playgroud)

到目前为止,我所能做的就是回复此错误:

Uncaught TypeError: Cannot read property 'document' of null
Run Code Online (Sandbox Code Playgroud)

我通过javascript而不是data-attribute启动模式,希望能够更好地挂钩回到父窗口:

jQuery的

$('#createemployeebtn').click(function (event) {
    $('#newemployeemodal').modal();
});
Run Code Online (Sandbox Code Playgroud)

没有这样的运气.

jquery twitter-bootstrap

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

Angular Material-关闭菜单时如何关闭/隐藏md-select?

我在中使用md-menu-item元素md-menu。菜单由一个按钮激活-一切正常,并且都使用默认的angular js。

在每个md-menu-item我都有md-select输入。看起来像这样:

...

<md-menu-item>
    <md-input-container>
        <label>My Label</label>
        <md-select name="myName" aria-label="My Label" ng-model="mv.myModel" ng-change="vm.onChangeEvent(foo)">
            <md-option ng-value="value" ng-repeat="foo in vm.bar | orderBy: 'name'">
                {{foo.name}}
            </md-option>
        </md-select>
    </md-input-container>
</md-menu-item>

...
Run Code Online (Sandbox Code Playgroud)

如果我通过单击按钮打开菜单-如果我什么也没有选择,然后单击<md-select>(屏幕上的任意位置),md-menu一切都会消失,一切都很好。

如果单击其中一个<md-select>元素,然后单击屏幕中的某个位置,则<md-menu>关闭,但仍可以看到该<md-select>元素。

有没有一种方法可以“嵌套”选择菜单项中的元素,以便在我关闭菜单项时也关闭所有子元素?

这是我所看到的Codepen示例

感谢您的任何建议!

angularjs angular-material

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

是否可以在同一页面上有多个 Grapesjs 实例?

我正在使用 Boostrap 4 标签。在每个选项卡上,我都有一个grapesjs 实例。一种是使用网页插件:

const productEditor = grapesjs.init({
            container: '#gjs',
            fromElement: 1,
            showOffsets: 1,
            allowScripts: 1,
            plugins: ['gjs-preset-webpage'],
            pluginsOpts: {
                'gjs-preset-webpage': {
                    // ... other options
                }
            },
            storageManager: {
                id: 'gjs-',
                type: 'remote',
                autosave: false,
                autoload: true,
                stepsBeforeSave: 3,
                urlStore: '',
                urlLoad: '',
                contentTypeJson: true
            },
            canvas: {},
        });
Run Code Online (Sandbox Code Playgroud)

另一个标签使用时事通讯插件

const newsletterEditor = grapesjs.init({
            container: '#newsletter-gjs',
            fromElement: 1,
            showOffsets: 1,
            allowScripts: 1,
            plugins: ['gjs-preset-newsletter'],
            pluginsOpts: {
                'gjs-preset-newsletter': {
                    modalTitleImport: 'Import template',
                    // ... other options
                }
            },
            storageManager: …
Run Code Online (Sandbox Code Playgroud)

grapesjs

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

Laravel Passport invalid_grant 用于密码 grant_type

我一直在尝试access_token为我的 api创建一个。我遵循了设置并使用 Postman 来测试/创建令牌。我似乎无法克服invalid_grant错误。

我已经尝试了我能找到的所有组合,但没有任何运气。这是我的设置:

发送POST请求至:http://mywebsite.local/oauth/token

在正文中,我设置form-data为这个(名称/值):

grant_type      password
client_id       1
client_secret   <super_long_string>
username        my@email.com
password        secret
Run Code Online (Sandbox Code Playgroud)

我使用 tinker 创建了一个虚拟用户:

factory('App\User')->create()
Run Code Online (Sandbox Code Playgroud)

我在上面使用新创建的用户作为我的用户名/密码。

不管我在做什么(没有传递任何东西),这是我总是看到的错误:

{
    "error": "invalid_grant",
    "error_description": "The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.",
    "hint": "",
    "message": "The provided authorization grant (e.g., …
Run Code Online (Sandbox Code Playgroud)

laravel laravel-passport laravel-6

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