我读了打字稿深入了解,我看到这两个let和const是块作用域,这是伟大的.显然,const不能改变(它是不可变的).但为什么ReSharper鼓励我改变尽可能多的lets const?我假设ReSharper认为使用const结束会有性能提升let?有没有之间的速度差const和let?是否有不同的使用理由const?请看以下示例:
for (let i = 0; i < this.InputControl.ParentQuestions.length; i++) {
const id = this.InputControl.ParentQuestions[i].ParentId;
const value = this.InputControl.ParentQuestions[i].ParentRequiredAnswer;
if (!formVals[id]) return false;
if (formVals[id].toLowerCase() != value.toLowerCase()) return false;
}
Run Code Online (Sandbox Code Playgroud)
以前,我有let id,let value但ReSharper要求我改变它们const,这有效,但为什么在这种情况下更好?或者无论如何?
我也在SO上发现了这个问题,但它更多地讨论了什么let和const做什么,而不是为什么一个比另一个好.它确实说const尽可能多地使用,但它提供了什么好处?
前几天,我试图找出如何选择select2 v3.5.1 JavaScript多选控件中的所有项目.我尝试了一些东西,但我很难搞清楚如何去做.我只想选择方框中的每个选项,但显然select2没有内置选项来为您选择所有项目.
我无法使Angular 2路由工作.我正在使用Angular 2和Webpack.在Angular 2 webpack启动器中,我注意到他们有webpack生成他们的html和他们的链接,但我希望我不必webpack我的html文件.
这是我的app.routes.ts ...
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from "./home/home.component";
import { ScheduleComponent } from "./schedule/schedule.component";
import { PageNotFoundComponent } from "./PageNotFoundComponent";
const appRoutes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'schedule', component: ScheduleComponent },
{ path: '**', component: PageNotFoundComponent }
];
export const appRoutingProviders: any[] = [
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
Run Code Online (Sandbox Code Playgroud)
这是我的@NgModule代码......
@NgModule({
imports: [
BrowserModule, …Run Code Online (Sandbox Code Playgroud) 我正在使用 Visual Studio 2015 Update 3。当我尝试使用 Resharper 重构我的 TypeScript 代码时,Resharper 尝试重构每个文件夹中的代码,包括node_modules. 显然,我不希望 Resharper 接触,node_modules因为那些是 3rd 方库(不是我的代码)并且可能需要 6 个小时来尝试浏览我在node_modules. 如何让 Resharpernode_modules在所有情况下都忽略,尤其是在重构过程中?
我已经尝试了以下方法:
我还尝试在其 Windows 文件夹属性中将 node_modules 文件夹更改为隐藏,但 Resharper 仍会进入该重构过程。
我还需要做什么才能让 Resharper 忽略node_modules?
我通过最新的 C# 驱动程序(此时为 v2.7.0)使用 MongoDB 4.0。我有一份文件,其中有Options和。换句话说,库存数组嵌套在选项数组中。如何了解库存水平并仅更新库存?OptionsInventory
以下是我的 JSON 格式文档的样子:
{
"Options": [
{
"Id": 1,
"Description": "This is one option",
"Inventory": [
{
"Id": 1,
"Name": "Box of stuff"
},
{
"Id": 2,
"Name": "Another box of stuff"
}
]
},
{
"Id": 2,
"Description": "This a second option",
"Inventory": [
{
"Id": 1,
"Name": "Box of stuff"
},
{
"Id": 2,
"Name": "Another box of stuff"
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
使用 C# 驱动程序,如果我知道选项的 Id …
我正在使用 Angular 4 Reactive Forms@angular/material版本2.0.0-beta.10。我需要以编程方式使md-error消息出现。
在必填字段上,当用户在没有输入任何文本的情况下留下输入时,我会显示md-error“此字段是必填字段”。见代码:
<md-form-field>
<input mdInput type="text"
formControlName="PartNumber"
placeholder="Part Number"
maxlength="250"
required />
<md-error *ngIf="formGroup.controls['PartNumber'].hasError('required')">
Part Number is <strong>required</strong>
</md-error>
</md-form-field>
Run Code Online (Sandbox Code Playgroud)
我都试过:
this.formGroup.markAsTouched();
this.formGroup.markAsDirty();
Run Code Online (Sandbox Code Playgroud)
在md-error下面的文字<input>时,我叫不出现markAsTouched()或markAsDirty()。
如何以编程方式触发触摸状态以显示错误消息?
当我从DocumentDB序列化JSON对象时,我Control没有OptionsControl使用Options属性反序列化为。
我的课程如下Control:
public class Control : IControl
{
public Guid Id { get; set; }
public virtual Enums.ControlType Type { get; set; }
public string PropertyName { get; set; }
public string ControlCssClass { get; set; }
public string Description { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我也有OptionsControl,它继承自Control:
public class OptionsControl : Control
{
public IDictionary<string, string> Options;
}
Run Code Online (Sandbox Code Playgroud)
我也有ClickableControl:
public class ClickableControl : Control
{
public string …Run Code Online (Sandbox Code Playgroud) Json.Net没有将其接收到的对象反序列化为我的 Control 类的正确派生类。(请参阅以下对该问题的解释。另请注意,我认为这是解释该问题所需的最少代码量。提前感谢您审阅此问题。)
我正在尝试将以下类序列化为 JSON 或从 JSON 反序列化。
public class Page {
public Guid Id { get; set; }
public Guid CustomerId { get; set; }
public IList<Control> Controls { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是 Control 类:
public class Control : ControlBase
{
public override Enums.CsControlType CsControlType { get { return Enums.CsControlType.Base; } }
}
Run Code Online (Sandbox Code Playgroud)
这是 ControlBase 抽象类:
public abstract class ControlBase
{
public Guid Id { get; set; }
public virtual Enums.CsControlType CsControlType { get; }
public …Run Code Online (Sandbox Code Playgroud) c# ×3
angular ×2
javascript ×2
json ×2
resharper ×2
typescript ×2
jquery ×1
json.net ×1
mongodb ×1
reflection ×1
webpack ×1