我正在尝试为表单字段/选择实现一个非常基本的验证。验证架构:
vehicleProvider: Yup.object() // This is an object which is null by default
.required('formvalidation.required.message')
.nullable(),
reserveVehicle: Yup.number().when('vehicleProvider', { // This is a number which is null by default
is: provider => provider?.hasReserve,
then: Yup.number()
.required('formvalidation.required.message')
.nullable(),
otherwise: Yup.number().notRequired()
}),
Run Code Online (Sandbox Code Playgroud)
我想要做的是:只需要/验证reserveVehicle如果provider.hasReserve是true。否则,不需要号码。我收到此错误:
“reserveVehicle 必须是一种
number类型,但最终值是:(NaN从值中转换NaN)。”
这是有道理的(有点)因为,null这不是一个数字。但是当我试图告诉它不应该要求它时,在我看来它不应该尝试评估它。
我是否错过了任何关键概念Yup?
检查底部的更新!
我有一个服务,在应用程序引导时抛出错误.Cannot read property 'call' of undefined.我正在使用ng2 2.4.2和angular-cli 1.0.0-beta.24.
错误
未捕获的TypeError:无法读取webpack_require(bootstrap 81b10f8 ...:52)的未定义属性'call',在Object.621(environment.ts:8)的webpack_require(bootstrap 81b10f8 ...:52)处于Object.450(src async:7) at webpack_require(bootstrap 81b10f8 ...:52)at object.1057(util.service.ts:35)at webpack_require(bootstrap 81b10f8 ...:52)at webpackJsonpCallback(bootstrap 81b10f8 ...:23)at main.bundle.js:1
正如您所看到的,它是util服务的问题 - 如下所示:
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Project } from '../datatypes/';
import { Response } from '@angular/http';
@Injectable()
export class UtilService {
constructor(private router: Router) {}
public redirectToProject(project: Project) {
let query = project.ProjectName.split(' ')
.join('-')
.concat('-' + project.Id)
.toLowerCase(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Sharepoint 2013上的其余api创建一个简单的列表项.我的代码:
$.ajax({
url: siteUrl + "/_api/web/lists/getByTitle('internal_Listname')/items",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify({
'__metadata': {
'type': 'SP.Data.internal_ListnameListItem',
},
'K1F1': k1f1Result,
}),
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
},
success: function (data) {
console.log("done");
},
error: function (err) {
console.log(JSON.stringify(err));
}
});
Run Code Online (Sandbox Code Playgroud)
尝试发送数据时,我收到403"禁止"错误.
"error":{
"code":"-2130575251, Microsoft.SharePoint.SPException",
"message":{
"lang":"en-US",
"value":"The security validation for this page is invalid and might be corrupted. Please use your web browser's Back button to try your operation again."
}
}
Run Code Online (Sandbox Code Playgroud)
以下代码有效.有没有一种更方便的方式,如果可能的话甚至是一个单行程?
const { nextUrl, posts } = await postService.getCommunityPosts(6);
this.communityPosts = posts;
this.nextUrl = nextUrl;
Run Code Online (Sandbox Code Playgroud)
我知道给出了结构化属性别名,但我不认为在这种情况下有帮助.MDN对此案没有任何说明.
我正在尝试使用angularfire构建一个ng2应用程序.在快速入门之后,我收到以下错误:
cannot find namespace 'firebase'
Run Code Online (Sandbox Code Playgroud)
似乎是打字的东西,虽然安装了所有这些.有关这个问题的任何想法?
我有一个带有两个输入字段(文本)的表单.从头开始创建(=无信息)效果很好.你可以猜到,也许我想稍后改变这些值.
问题:当仅更改描述时(并将标题保留为服务器),标题将无效.如果我将最后一个char(Testproject更改为Testproject2)更改,例如它可以工作.我需要改变什么?
模板:
<form [formGroup]="projectEditForm" novalidate>
<div [formGroup]="projectEditForm">
<label>Title</label>
<input type="text" [class.validationError]="projectEditForm.controls.Title.invalid && (projectEditForm.controls.Title.dirty || submitted)"
value="{{ (project | async)?.ProjectName }}" formControlName="Title">
<label>Description</label>
<textarea [class.validationError]="projectEditForm.controls.Description.invalid && (projectEditForm.controls.Description.dirty || submitted)"
value="{{ (project | async)?.Description }}" formControlName="Description"></textarea>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
表格型号:
this.projectEditForm = this._fb.group({
Title: ['', [<any>Validators.required, <any>Validators.minLength(5)]],
Description: ['', [<any>Validators.required]]
});
Run Code Online (Sandbox Code Playgroud) 据我所知,最佳做法是在更新项目后返回它。TypeORM的updateByIdreturns void,但不是更新的项目。
我的问题:是否可以在一行中更新并返回修改后的项目?
到目前为止我尝试过的是:
await this.taskRepository.updateById(id, { state, dueDate });
return this.taskRepository.findOne({ id });
Run Code Online (Sandbox Code Playgroud)
我在寻找什么:
return this.taskRepository.updateById(id, { state, dueDate }); // returns updated task
Run Code Online (Sandbox Code Playgroud) 假设我有一个包含一些数据的对象。我想为所有类型构建一个通用映射器(分别只有一个函数 - 我不想一直实例化一个新类),以便像这样使用:this.responseMapper.map<CommentDTO>(data);
它应该简单地从给定类型中获取所有属性并将数据映射到它。到目前为止我尝试过的:
public map<T>(values: any): T {
const instance = new T();
return Object.keys(instance).reduce((acc, key) => {
acc[key] = values[key];
return acc;
}, {}) as T;
}
Run Code Online (Sandbox Code Playgroud)
new T(); 会抛出错误: 'T' only refers to a type, but is being used as a value here.
这样做的正确方法是什么?
我们有一个应该实现 rbac 的 Nest 应用程序。我根据守卫文档为其添加了一个基本的守卫和装饰器: https: //docs.nestjs.com/guards。问题:这仅允许静态角色。
我们的目标:在我们的例子中,我们有一个Contract实体。仅当合同的承包商 ( <User>) 或承包商的主管 ( <User>) 尝试访问该合同时,才应加载该合同。我不想实施诸如此类的事情,if (contract.contractor.id === user.id)因为我们有很多不同的情况,随着时间的推移,这会让事情变得一团糟。
它看起来像下面这样:
@Get()
@Roles(ROLES.ADMIN, ROLES.CONTRACTOR, ROLES.SUPERVISOR)
getContractById(...): Contract {
return this.contractService.findById(...);
}
Run Code Online (Sandbox Code Playgroud)
当然,ROLES.SUPERVISOR只是一个字符串,然后与用户的静态角色进行匹配。所以问题是:如何使用动态角色来实现类似的功能,例如主管角色,它仅在某些项目的上下文中是动态的。
我决定删除节点模块文件夹,npm install然后做一个npm run serve它总是卡在 40% 左右并永远停留在那里。从 UI 完成后,它也会卡在类似的数量上:
$ vue-cli-service serve --open --mode development --https --dashboard INFO 正在启动开发服务器...
40% 构建 118/134 个模块 16 个活动 ...tApp\node_modules\axios\lib\defaults.js
下一次:
40% 构建 134/147 个模块 13 个活动 ...\node_modules\axios\lib\adapters\xhr.js
我注意到 Node.js 进程一直以 15% 左右的速度运行,但如果我等待、等待和等待,什么也不会发生。
{
"name": "myapp",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"test:e2e": "vue-cli-service test:e2e",
"test:unit": "vue-cli-service test:unit"
},
"dependencies": {
"@aspnet/signalr": "^1.1.4",
"axios": "^0.18.0",
"vue": "^2.6.10",
"vue-axios": "^2.1.4",
"vue-router": "^3.0.6", …Run Code Online (Sandbox Code Playgroud) javascript ×4
angular ×3
typescript ×3
rest ×2
ajax ×1
angularfire2 ×1
api-design ×1
class ×1
ecmascript-6 ×1
firebase ×1
forms ×1
json ×1
mapping ×1
nestjs ×1
node.js ×1
object ×1
orm ×1
rbac ×1
reactjs ×1
roles ×1
service ×1
sharepoint ×1
typeorm ×1
validation ×1
vue-cli ×1
vue.js ×1
webpack ×1
yup ×1