所有问题
javascript - 实现rest html前端PATCH
我是新手。为了练习,我目前正在使用 nodejs 和 express 创建一个 REST API,具有以下端点:
- 获取 site.tld/project/21 -> 显示项目 21
- 发布 site.tld/project/33 -> 创建项目 33
- PATCH site.tld/project/44 -> 更改项目 44
- 删除 site.tld/project/55 -> 删除项目 55
ETC
我想要一个网站来显示、创建、修补和删除项目。所以我通过javascript在浏览器中实现了REST客户端。我用 Bootstrap 构建了一个不错的前端。要将 PATCH 请求从前端发送到后端,我使用带有 fetch() 的脚本,
现在我的问题:
如果我想向 API 发出 HTTP PATCH 或 DELETE 请求,我需要项目的 ID。如何在前端获取项目的 ID?
我发现了以下可能性:
在前端获取并提取带有 window.location.href 的 URL,因为要编辑项目的网页的 URL 包含 ID,例如:url 为“site.tld/project/33”,因此 ID 为“33”。
我使用 ejs 模板,我可以将 ID 从后端发送到前端,并将数据绑定到 html data-* 标签并通过 javascript 提取它。
这些都感觉不对。有人可以向我解释正确的方法是什么吗?
oauth-2.0 - 谷歌操作没有 webhook 调用帐户取消链接
我正在开发一个谷歌助手集成,当涉及到帐户取消链接时,我发现谷歌存在一些限制。当我们从模拟器设置中取消链接帐户时,它只会在 google 端取消链接,google 不会执行任何 webhook 调用来通知托管 webhook 的主机,这会使帐户在服务器端保持链接。我期待来自 google 的取消链接的 webhook 调用,因此这些帐户也可以在我的主机上取消链接。想检查是否有人遇到过这个问题并有其他替代方案来解决这个问题?
c# - Razor 页面无法验证策略
我正在使用 VS 2019、带有 Razor Pages 的 ASP.Net Core 5(不是 MVC)。我有一个带有授权策略的简单 Razor 页面。下面是代码的摘录,我在这篇文章中对其进行了一些简化,并用文字替换了全局常量。
剃刀页面指令:
[授权(策略 = “AuthUsers”)]
Startup.cs 中描述了该策略
services.AddAuthorization(options =>
options.AddPolicy("AuthUsers", policy => policy.RequireClaim("Users")));
登录页面使用上述声明创建声明主体,如下所示:
var Claims = new List { new Claim(ClaimTypes.Email, Input.Email)) }; Claims.Add(new Claim("Users", "1")); var claimIdentity = new ClaimsIdentity(Claims, CookieAuthenticationDefaults.AuthenticationScheme); ClaimsPrincipal claimPrincipal = new ClaimsPrincipal(claimsIdentity);
成功登录后,我验证声明已正确设置,但每次我进入剃须刀页面时,它都会返回登录页面进行授权,即使用户已明确登录并且“注销”链接处于活动状态。
java - 从具有多个源的 FrameLayout 中删除子片段的正确方法
我有一个 FrameLayout,它可以根据用户在 RadioGroup 上的选择填充不同的片段。然而,我很确定我用来去除这些碎片的方法远非理想,如果可能的话,我想了解如何正确地做到这一点。
我现在如何删除碎片:
但是,我知道这种方法远非完美,因为如果我在 之外的任何时候调用它radioGroup.SetOnCheckedChangeListener,它不会删除当时暴露的片段。所以我的问题是:从可以容纳不同类型片段的 FrameLayout 中删除片段的正确方法是什么?为什么我的removeFragments()方法在此侦听器上使用时有效,但在代码中的其他点调用时无效?
javascript - 根据输入值向数组的值添加/应用函数
我正在尝试随着数据输入的变化(由用户)更改饼图的值。
对于上下文,我目前有 4 个参数,称为 Ativo(其中 5 个)、配额(每个设置为 20%、100% 除以 5 个 ativos)、Perda 潜力(每个设置为 0,最大值为 100%)和 Perda (最初设置为 0,但将是累积的)。随着 perda 潜力的增加,配额将以 1:5 的比例减少,反之亦然(例如,如果 perda 潜力 = 20%,那么配额将为 16%。Perda 潜力增加 1% = 配额减少 0.2% )
我现在想从输入的更新值中获取原始配额 (20%) 和新配额之间的差异(以前面的示例为例,这将是 20% - 16% = 4%)并保存在Perda 变量。然后这个 perda 将作为饼图添加,而新配额为 16% 的 Ativo 将在饼图上更新(例如,如果我们想更改第一个 Ativo 并放置前面示例中的值,我们将从 5 个饼片中的 1 个 20% 变为 6 个饼片,一个新配额为 16%,另一个 perda 为 4%,另外 4 个饼片将保持 20%,因为它们没有更改)。此 perda 值将是累积的,因此如果任何其他配额发生更改,perda 将对这些值求和。
代码正在更新图表(增加perda potencial%会减少quota%并在按下按钮后改变饼片的值),但是为perda添加的饼片基本上是最后改变的配额的值而不是两者之间的差异原配额和新配额。
netlogo - 代理死亡肯定会影响代理正在运行的“while”循环吗?
正如下面的测试所示,如果海龟while在死时正在运行 a,则它会中断while(没有任何错误)。NetLogo 是否保证这种行为?
javascript - Filter multiple pokemons of PokeApi
I make a request to 'https://pokeapi.co/api/v2/pokemon/${name}' to obtain the information of a specific pokemon, the problem is that the name must be the same otherwise it returns undefined, I need to filter many pokemons, for example: if I search for char it should return charmeleon and charizard, because they both have 'char'. How can I filter a lot of pokemons?
google-sheets - Copy value from a cell to the rest of a colum
Is there someone who can help me to break down this long formula and ,by examining the independent elements, help us to understand how it works?
It takes two contiguous columns, in this case A and B. First a value from A is taken. If there is a next value down A, it will repeat the actual value until that row. If there's no values left in A, it return "" (blank)
So, in "B1" we write this very long formula:
ArrayFormula(IF(ROW(A:A)<=MATCH(2;1/(A:A<>"");1);LOOKUP(ROW(A:A);ROW(A:A)/IF(A:A<>"";TRUE;FALSE);A:A);))
The result is like this:
| A | B |
|---|---|
| foo | foo (here goes the formula) |
| foo | |
| bar | bar |
| bar | |
| bar | |
| qux | qux |
| " " | |
| " " | |
| " " | |
| " " (blank cells continue till the end of column) |
This array is quite useful, but I guess if there is a cleaner formula, or a better approach to this task... I suspect thats this formula is a turnaround and Spreadsheets must have an elegant resource to get done this kind of task.
c# - Sending email to multiple recipients fails
I am trying to send the same automatic email to multiple email addresses but I can't get it to work.
When I send an email to a single address, it works. Like so: var emailService = new Email { To = "info@tel.net" };
but when I try something like this, it doesn't send the email var emailService = new Email { To = "info@tel.net, info@gmail.com" };
I also tried separating the address like so var emailService = new Email { To = "info@tel.net; info@gmail.com" }; but this also doesn't work.
Any suggestions?
laravel - Custom login property Laravel 8
I have this custom function for atempting to login in Laravel 8
How I can make to accept the login atempt when $credentials['estado'] also has 2 as value.
Don't know how to make it accept multiple values.
I managed to make the custom function accept the value of 1 but dunno how to make it accept multiple $credentials['estado'] values.
php - Get week range with timezone
I'm trying to get week range for a given date. I use the below code to do so.
How can I make it work so it take timezone into account? My timezone is GMT+1 but the returned date has - 1 hour difference
python - Pygame window closes right after
When I run this code, the pygame window closes right after while using Virtual Studio Code. While using Jupyter notebook it runs but goes unresponsive after 2-3 seconds. Both of them do not display any errors though.
kubernetes - Is there any way to know when a PVC is mounted last time in k8s?
Is there any way to know when a PVC is mounted last time in k8s?
Thank you for your help
flutter - how to solve "Execution failed for task ':app:compileFlutterBuildDebug"
I was trying to run my Flutter app and this shows up:
I do flutter clean, I delete pubspec.lock
FAILURE: Build failed with an exception.
Where: Script '/Users/mac/development/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1005
What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'.
Process 'command '/Users/mac/development/flutter/bin/flutter'' finished with non-zero exit value 1
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 21s Exception: Gradle task assembleDebug failed with exit code 1
azure - Azure 静态网站使用我自己的 ssl 证书?
我有自己的证书,我想与 azure 静态网站一起使用(不是 web 应用程序,我们使用基于 blob 存储的证书),但看起来不支持上传我自己的证书,是否有任何解决方法或解决方案?注意:静态网站是私有的,带有privatelink,dns名称是私有的(仅用于内部网络,内部有我们自己的dns服务器)
r - 绘制瑞利商的等高线图以验证函数的最小值和最大值
定义
可视化x ∈ [−3, 3]^2\{ 0 }的瑞利商 f( x ) = R A ( x ) 的图,并生成 f 的等高线图。使用此可视化来验证 f 的最大值和最小值,以及作为最大值和最小值的x集合。
我知道,
但我不确定如何设置 x 的函数,然后在 R 中绘制等高线图。任何方向都会有帮助,谢谢!
node.js - 使用 typescript 定义来验证 POST 正文请求
我正在编写一个 API,我想在 POST 正文中检查所需的参数。也可以有可选参数。例如:
在 ExpressPOST /User/create实现中,我想检查主体是否包含在MOST(即,对于不在定义中的属性将引发错误):
API 将与前端代码共享这些定义。
我的问题是 Node 是否有办法在运行时解析该类型定义,这样我就不必手动检查所有必填字段并阻止不应该成为正文一部分的字段。
就像是:
javascript - 全局 onclick 处理程序与每个元素事件处理程序
考虑这个例子:
您正在创建一个使用客户端渲染的网站。当用户单击链接时,您希望禁用浏览器的导航并自己呈现新页面。
也许你也有一些这样的html,并且你想在upvote_post(id)每次点击按钮时调用:
处理这两种情况的常用方法是在您生成的每个 、 等元素上添加一个事件处理click程序。<a><upvote-button>
但是在文档本身上添加一个事件处理程序不是更好吗?
当然,绕过内置事件处理程序系统感觉不对,但我想不出这里有什么缺点。
如果需要,您仍然可以将事件处理程序添加到特定元素,但对于常见操作,这似乎是一个更好的解决方案。
javascript - 4000 毫秒后重试超时:无法读取未定义的属性(读取“toLowerCase”)
当我尝试通过 cypress 执行断言并且只需要一些帮助时,我收到了一个奇怪的错误。我要做的只是显示一个选项已添加到投注单中。
我收到的错误是:
这发生在这一步:
它指向的元素是:
git - 多用户机器上的本地 Git LFS 存储库
我已经在多用户机器上建立了一个启用 LFS 的存储库,这样从事项目的其他人可以共享超过我们私有 GitLab 实例配额的大型专有文件。为避免冲突,我们让一个人(我)将主副本保存在他们的主目录中,并定期使用git fetch和git merge合并他们本地克隆的更改。
本地克隆都按预期工作。它们是用 创建的git clone /home/[MY USERNAME]/[REPO],并且更改在本地提交而不会出现问题。
但是,当我尝试合并他们的更改时,出现以下错误。
有趣的是,在收到错误后,我尝试合并的提交中存在所有非 LFS 跟踪文件的未跟踪副本。
日志文件不包含太多额外信息,除了以下环境信息:
这是输出git config -l
我是否错误地配置了 git-lfs?有没有替代方法可以避免这个问题?我们确实需要本地托管的所有内容,因为这些文件是专有的。
json - 如何阻止 Jinja 向 JSON 数组添加单引号?
当我对数组使用单个模板值替换时,jinja 会向数组中添加一个额外的单引号块。我不想要额外的单引号。是否有可能做到这一点?我目前的方法是手动重建阵列。我在 python 脚本中使用 jinja2。
IE
替换型号:
损坏的模板:
结果:
"powers: ['"Radiation Resistance"','"Turning Tiny"','"Radiation blast"']
我想要的结果:
"powers: ["Radiation Resistance","Turning Tiny","Radiation blast"]
Jinja 插件不断向 json 数组中的项目添加单引号,尽管它没有它们。我尝试转义等,但似乎没有任何效果,也找不到任何以前提出的问题。
我“修复它”的方法是在模板中重建数组,但这似乎是一个糟糕的解决方法,对于一个包含 100 个项目的数组来说是不可行的。
这是原始文档片段
这是我正在使用的模板,为了复制原始模板 - 我必须做一些“hacky”并且基本上手动重新创建数组。这似乎并不理想,对于大型阵列来说会很笨重
有一个更好的方法吗?当我对数组使用单个模板值替换时,jinja 会向数组添加一个额外的单引号块
javascript - 如何在 react-native 中制作弹跳按钮动画
如果我们使用 css,我们可以通过
但问题是,react-native,我们不能使用类似的库web-kit,所以我想知道如何为按钮或更大的视图制作弹跳动画,如何在 react-native 应用程序中制作动画?



