我有一个允许匿名的 API 端点。我已经在 Postman 中确认它适用于匿名和经过身份验证的用户并返回正确的 JSON。
由于可以匿名调用端点,因此在我的 Blazor WASM http 服务中,我构建了以下内容:一个不带令牌发送的请求,一个带令牌发送的请求。
private readonly HttpClient httpClient;
private readonly IHttpClientFactory httpClientFactory;
private readonly HttpClient anonHttp;
public CommunityHttpService(HttpClient httpClient, IHttpClientFactory httpClientFactory)
{
if (httpClient == null) throw new ArgumentNullException("Http is null.");
this.httpClient = httpClient;
this.httpClientFactory = httpClientFactory;
anonHttp = httpClientFactory.CreateClient("AnonAPI");
}
public async Task<HttpResponseMessage> GetCommunity(Guid communityId, bool userIsAuthenticated)
{
if (!userIsAuthenticated)
{
// make anonymous api call without bearer token to avoid error
return await anonHttp.GetAsync($"api/communities/GetCommunity/" + communityId);
}
else
{
return await …Run Code Online (Sandbox Code Playgroud) 这是一个愚蠢的问题,因为我觉得我应该知道答案并认为我的代码可以完成这项工作。
但是我正在使用引导程序并且我试图将 btn btn-primary 类从默认的蓝色更改为其他内容。
这是我的 html:
<input type="text" class="form-control" placeholder="Search by user name, member type, genre...">
<span class="input-group-btn">
<button class="btn btn-primary" type="button"><i class="fa fa-search" aria-hidden="true"></i></button>
</span>
Run Code Online (Sandbox Code Playgroud)
还有我的 CSS:
.btn btn-primary:hover,
.btn btn-primary:focus,
.btn btn-primary:active,
.btn btn-primary.active {
color: #ffffff;
background-color: pink;
border-color: pink;
}
Run Code Online (Sandbox Code Playgroud)
但它仍然是这样的:
我是Javascript/jQuery的新手,我正在尝试根据用户输入到表中来构建项目列表.
这里的想法是用户将文本输入到表单中,js/jQuery将捕获该数据并将其显示为boostrap4表中的一行.
我得到它,以便当用户输入时,它将数据添加为一行(见图),但是,我需要它才能工作,这样当用户点击红色的"删除"按钮时,它会删除整个表格 - 行.现在,它只是在我点击它时删除按钮(见第三张图片).
这是我的HTML:
<div class="tab-pane fade" id="watchlist" role="tabpanel" aria-labelledby="watchlist-tab">
<h2 class="display-4">Watch List</h2>
<p class="lead">Add series to your watch list and receive an e-mail notification when new data is available.</p>
<p class="card-text">
<div class="form-check form-check-inline">
<span class="mr-2">How would you like to receive your e-mail notifications?</span>
<label class="form-check-label" data-toggle="tooltip" data-placement="top" title="Get email updates on your series bundled in one single daily email.">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1"> Daily Digest
</label>
</div>
<div class="form-check form-check-inline" data-toggle="tooltip" data-placement="top" title="Get an …Run Code Online (Sandbox Code Playgroud) 我实际上是在创建一个博客(命名约定略有不同).我的"post"类(我称之为故事)上有一个属性,它与一个名为"visibility"的表相关联.帖子可以是公开的也可以是私人的.
当用户查看其他成员的个人资料时,他们应该能够看到所有公开发布的帖子.
我创建了一个viewmodel:
public class UserDetailsViewModel
{
public bool IsRegisteredUser { get; set; }
//public bool IsStoryPrivate { get; set; }
public int StoryCount { get; set; }
public int ReviewCount { get; set; }
public ApplicationUser User { get; set; }
public virtual IEnumerable<Story> Stories { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在我的用户控制器中,当有人点击配置文件以查看配置文件的详细信息时,我从数据库中获取用户,获取与该用户关联的所有故事(帖子)并包含与帖子关联的各种表格,获取帖子数量,并将这些值插入我的视图模型.这是通过以下代码完成的:
public ActionResult Details(string id)
{
//verify an id was passed
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
//if an id was given as a parameter, find …Run Code Online (Sandbox Code Playgroud) 我有一个长达数百个元素的数据集.我需要循环遍历数组和对象,并确定它们中的数据是否小于某个数字(在我的例子中为0).如果是,我需要从数据集中删除所有小于零的数据点.
我试过.pop和.slice,但我没有正确实现它们.我试图将坏数据推送到自己的数组中,只剩下好的数据.
这是我的JS
for (var i = 0; i < data.length; i++) {
if (data[i].high < 0) {
console.log(data[i].high)
var badData = [];
badData.push(data.pop(data[i].high));
console.log(data[i].high)
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个用户模型架构、一个工作模型架构和一个评论模型架构。这些模式之间的关系是用户可以提交许多作品(如博客文章),并且可以评论/评论(我们称之为批评)其他人的文章(作品)。
因此,当用户提交评论(将其视为评论)时,这就是我的发布路线。我通过 id 找到工作,然后创建一个新的评论模型对象,并将其传递给 .create() mongoose 函数。一切似乎都很顺利,直到我上foundWork.critiques.push(createdCritique)线。控制台记录错误说:
BulkWriteError:E11000 重复键错误集合:zapper.critiques 索引:username_1 dup 键:{:空}
显然,这是说对象中有两个用户名键并且它们相互冲突,但我对此不够熟悉,无法找到问题的根源并在猫鼬模型中修复它。模型如下。如果有人可以提供帮助,那将不胜感激。
// post route for getting the review
router.post('/:id', isLoggedIn, function(req, res) {
Work.findById(req.params.id, function(err, foundWork) {
if (err) {
console.log(err);
} else {
// create a new critique
var newCritique = new Critique ({
reviewerName: {
id: req.user._id,
username: req.user.username
},
work: {
id: foundWork._id,
title: foundWork.title
},
critique : req.body.critique,
date: Date.now(),
rating: 0
});
// save new critique to db
Critique.create(newCritique, function(err, createdCritique) …Run Code Online (Sandbox Code Playgroud) 我有一个解析器,该解析器从服务中获取数据,并将该Observable对象传递给订阅并实现解析器的组件。
resolve (route: ActivatedRouteSnapshot): Observable<NewsAPIArticle[]> {
return this.newsAPIService.getNewsAPIArticles()
.pipe(
catchError(error => {
this.alertify.error('Problem retrieving news');
return of(null);
}),
take(5)
);
}
Run Code Online (Sandbox Code Playgroud)
在组件的ngOnInit中,我获取数据,将其保存到本地数组,然后控制台记录该数组。
ngOnInit() {
this.router.data.subscribe(data => {
this.articles = data['news']['articles'];
console.log(this.articles);
this.language = 'en';
});
}
Run Code Online (Sandbox Code Playgroud)
但是,按照我的理解,解析器不应该从控制台记录5件事,而是应从可观察对象中“取走”,而是返回20个对象。我在take rxjs运算符中做错了什么?我不希望所有20个回复,可能只有5个。
我正在努力使用 Azure Devops 中的替换令牌任务将变量发送到 Blazor 服务器应用程序中的 appsettings.json 文件。
在 中appsettings,我有这个:
{
"version": "#{versionNumber}#"
}
Run Code Online (Sandbox Code Playgroud)
在 Azure DevOps 中,我设置了以下变量:
versionNumber: '$(version.Major).$(version.Minor).$(version.Revision)'
Run Code Online (Sandbox Code Playgroud)
我的 ReplaceToken 任务是:
- task: replaceToken@3
displayName: "Replacing version in appsettings"
inputs:
targetFiles: '**/*.appsettings.json'
encoding: 'auto'
writeBOM: true
actionOnMissing: 'warn'
keepToken: false
tokenPrefix: '#{'
tokenSuffix: '}#'
useLegacyPattern: false
enableTelemetry: true,
verbosity: detailed
Run Code Online (Sandbox Code Playgroud)
但是,在构建管道中我看到:
replaced 0 tokens out of 0 in 0 file(s) in 1.17 seconds
Run Code Online (Sandbox Code Playgroud)
对我在这里做错了什么有帮助吗?
bootstrap-4 ×2
css ×2
html ×2
javascript ×2
angular ×1
arrays ×1
asp.net-mvc ×1
azure ×1
azure-devops ×1
blazor ×1
c# ×1
jquery ×1
mongodb ×1
mongoose ×1
node.js ×1
rxjs ×1