在这里,我在自动完成下拉列表中获得了国家/地区列表,并尝试通过国家/地区名称的开头字母来过滤这些国家/地区。
示例:如果我们输入“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) 我在 FormArray 方面遇到问题,可能需要一些帮助。\n我有一个带有变量 FormArray 的表单,它可以工作,我可以将数据发送到后端。\n问题是,我无法设置从我收到的数据中的值后端。
\n这是打字稿代码:
\nthis.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})\nRun Code Online (Sandbox Code Playgroud)\n然后在 html 中单击按钮,我调用此函数:
\naddActor(){\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}\nRun 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) 我想在一个标签中设置两个值。例如,如果我打开下拉菜单,它应该显示为:
“值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) 这是 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) 我有这个查询在 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)
不起作用..我做错了什么?
我在聚合管道的第一阶段使用以下方法得到了这组结果$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,而不是解析所有它们。
我该怎么做?
我正在 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) 我想转换以下 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) 如何放入服务的可变响应,然后在悬停时显示它?我试过这个:
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”
有什么建议吗?
angular ×4
c# ×4
mongodb ×3
typescript ×3
asp.net-core ×2
.net-6.0 ×1
aggregation ×1
autocomplete ×1
converters ×1
filter ×1
formarray ×1
json ×1
mongoose ×1
nosql ×1
primeng ×1
promise ×1