小编Yon*_*hun的帖子

Angular Autocomplete - 按单词的开头字母进行过滤

在这里,我在自动完成下拉列表中获得了国家/地区列表,并尝试通过国家/地区名称的开头字母来过滤这些国家/地区。

示例:如果我们输入“Aus”,则所有带有“aus”的国家/地区名称都会被过滤。(参见屏幕截图)。我只想过滤“澳大利亚和奥地利”或以“Aus”开头的任何其他国家/地区名称。

怎么做?

在此输入图像描述

<ng-autocomplete #countryList formControlName="locationCountry" [data]="countries"
   min-length="1" [searchKeyword]="countrykeyword"
   [initialValue]="countrykeyword"
   (selected)='selectEventCountry($event);onLocationSubmit();'
   (inputCleared)='onCountryCleared($event, false)'
   [itemTemplate]="countryListTemplate"
   [notFoundTemplate]="notFoundTemplate" placeHolder="Enter Country">
</ng-autocomplete>
Run Code Online (Sandbox Code Playgroud)

autocomplete filter typescript angular

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

Angular FormArray setValue 与来自服务的数据

我在 FormArray 方面遇到问题,可能需要一些帮助。\n我有一个带有变量 FormArray 的表单,它可以工作,我可以将数据发送到后端。\n问题是,我无法设置从我收到的数据中的值后端。

\n

这是打字稿代码

\n
this.form = this.fb.group({\n  title: new FormControl("",[Validators.required]),\n  actors: new FormArray([])\n})\n\nthis.moviesService.getMovie(this.movieId).subscribe(movieData => {\n  this.movie = movieData;\n  this.form.patchValue({\n    title: this.movie.title,\n    actors: this.movie.actors,           \n  })\n})\n
Run Code Online (Sandbox Code Playgroud)\n

然后在 html 中单击按钮,我调用此函数

\n
addActor(){\n  const actorsForm = this.fb.group({\n    actor: \'\',\n    role: \'\'\n  })\n  this.actors.push(actorsForm);\n}\n\nremoveActor(i: number){\n  this.actors.removeAt(i);\n}\n
Run Code Online (Sandbox Code Playgroud)\n

和 HTML:

\n
<form [formGroup]="form" (submit)="onSubmit()">\n  <table  formArrayName="actors">\n    <tr>\n      <th colspan="2">Besetzung:</th>\n      <th width="150px">\n        <button type="button" mat-stroked-button color="primary" (click)="addActor()">Hinzuf\xc3\xbcgen +</button>\n      </th>\n    </tr>\n    <tr *ngFor="let actor of form.get(\'actors\')[\'controls\']; let i=index" [formGroupName]="i">\n      <td>\n …
Run Code Online (Sandbox Code Playgroud)

typescript angular angular-reactive-forms formarray

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

PrimeNG 下拉菜单 - 如何在一个选项标签中设置两个值

我想在一个标签中设置两个值。例如,如果我打开下拉菜单,它应该显示为:

“值1 值2”

与空间在一条线上。value1数据value2是从数据库中获取的。我尝试使用下面的方法,但没有成功。

<p-dropdown [options]="divitionArr" name="business_divition" [(ngModel)]="project.business_divition" optionLabel="{'first_name','last_name'}" optionValue="divition" #diviSel="ngModel"></p-dropdown>
Run Code Online (Sandbox Code Playgroud)

primeng angular primeng-dropdowns

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

MongoDB - 如何将字符串转换为日期并执行过滤器

在此输入图像描述

在执行过滤器以获取大于当前日期的所有日期之前,如何将类型的字段日期转换String为?Date谢谢!

mongoose mongodb mongodb-query

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

ModelState.IsValid 包含导航属性。总是假的。(仅限net-6.0)如何实现?

这是 dotnet 上的一个示例。github.com/dotnet...我在 net-6.0 版本上工作

验证检查的结果为 false,因为该类的导航属性参与了验证。我在 net-5.0 上实现了一个简单的实验 - 导航属性没有反映在结果中。但是,也许我错了。

如何正确解决这个问题呢?

public class Course
{
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    [Display(Name = "Number")]
    public int CourseID { get; set; }

    [StringLength(50, MinimumLength = 3)]
    public string Title { get; set; }

    [Range(0, 5)]
    public int Credits { get; set; }

    public int DepartmentID { get; set; }

    public Department Department { get; set; }
    public ICollection<Enrollment> Enrollments { get; set; }
    public ICollection<CourseAssignment> CourseAssignments { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

CoursesController.cs

// …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-mvc asp.net-core .net-6.0

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

如何使用 C# 在 MongoDb 查找查询中使用多个过滤器

我有这个查询在 datagrip 中运行良好

test> db.getCollection("comments").find({status: {$ne: "APPROVED"},storyID: {$regex: "bbjfn-*"}})
Run Code Online (Sandbox Code Playgroud)

我只是想知道如何使用 MongoDB Driver 2.13.1 在 C# 中实现同样的功能

IMongoDatabase database = MongoClient.GetDatabase(Program.Settings.MongoDB.Database);
IMongoCollection<BsonDocument> collection = database.GetCollection<BsonDocument>("comments");

var filter = Builders<BsonDocument>.Filter.Eq("status", new BsonDocument("$ne", "APPROVED")) & 
Builders<BsonDocument>.Filter.Eq("storyID", new BsonDocument("$regex", "bbjfnfn-*"));

var results = await collection.FindAsync(filter);
Run Code Online (Sandbox Code Playgroud)

不起作用..我做错了什么?

c# mongodb mongodb-query mongodb-.net-driver

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

如何 $push 聚合中的所有文档而不是特定字段

我在聚合管道的第一阶段使用以下方法得到了这组结果$match

[
  { a: 1, b: 2 },
  { a: 3, b: 4 }
]
Run Code Online (Sandbox Code Playgroud)

现在我想对所有 A 和 B 求和,并且仍然保留它们,因此我将得到如下结果:

{
  total_sum: 10,
  items: [...] // first and second objects ofcourse
}
Run Code Online (Sandbox Code Playgroud)

我尝试过$group$push但是,push 只从对象中推送特定字段,我需要命名 A 和 B,而不是解析所有它们。

我该怎么做?

aggregation mongodb nosql aggregation-framework

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

ASP.NET Core Web API - 尝试激活“Services.CurrentUserService”时无法解析类型“IHttpContextAccessor”的服务

我正在 ASP.NET Core-6 Web API 用户身份验证登录中实现 CurrentUser 服务。我正在使用 IdentityDbContext:

当前用户服务:

public interface ICurrentUserService
{
    public string UserId { get; }
    public string UserName { get; }
    bool IsAuthenticated { get; }
    public string IpAddress { get; }
}
Run Code Online (Sandbox Code Playgroud)

当前用户服务:

using Microsoft.AspNetCore.Http;
using System.Security.Claims;

public class CurrentUserService : ICurrentUserService
{
    public string UserId { get; }
    public string UserName { get; }
    public bool IsAuthenticated { get; }
    public string IpAddress { get; }

    public CurrentUserService(IHttpContextAccessor httpContextAccessor)
    {
        IpAddress = httpContextAccessor.HttpContext?.Connection?.RemoteIpAddress.ToString(); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core asp.net-core-webapi

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

System.Text.Json JsonConverter 字符串数组到单个字符串

我想转换以下 JSON。如您所见,该数组只有一个条目。我想将其转换为一个简单的字符串。

{
    "@timestamp": [
        "2022-05-24T01:53:32.600Z"
    ],
    "site.siteCode": [
        "ZAR"
    ],
    "username": [
        "QR02159T1"
    ]
}
Run Code Online (Sandbox Code Playgroud)

我尝试JsonConverter使用System.Text.Json创建一个,但尽管添加了转换器,但它从未调用。

我的转换器:

{
    "@timestamp": [
        "2022-05-24T01:53:32.600Z"
    ],
    "site.siteCode": [
        "ZAR"
    ],
    "username": [
        "QR02159T1"
    ]
}
Run Code Online (Sandbox Code Playgroud)

该模型:

public class ArrayToSingleConverter : JsonConverter<string>
{
    public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        if (reader.TokenType == JsonTokenType.StartArray)
        {
            // Proper array, we can deserialize from this token onwards.
            // return JsonSerializer.Deserialize<List<string>>(ref reader, options);
        }

        throw new NotImplementedException();
    }

    public …
Run Code Online (Sandbox Code Playgroud)

c# json converters jsonconverter system.text.json

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

类型“Promise&lt;string&gt;”不可分配给类型“string”

如何放入服务的可变响应,然后在悬停时显示它?我试过这个:

toolTip: string;

async mouseover(params) {
    this.handle = setTimeout(() => {
        this.toolTip = this.checkSaldo(10, 'FRA');
        this.show = true;
    }, 4000);

}

checkSaldo(amount: any, currencyCode: any): Promise<string> {
    return new Promise((resolve) => {
        this.restService.getByParam('recalculatedSaldo', { amount: amount, currency: currencyCode }).subscribe(response => {
            resolve(response.payload);
        });
    })

}
Run Code Online (Sandbox Code Playgroud)

但我在变量上遇到错误toolTip

类型“Promise”不可分配给类型“string”

有什么建议吗?

promise typescript angular

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