我正在创建一个ASP.NET Core API应用程序,并依赖于EF Core.我有像这样定义的实体:
public class AppUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
[InverseProperty(nameof(Post.Author))]
public ICollection<Post> Posts { get; set; } = new List<Post>();
}
public class Post
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string AuthorId { get; set; }
[ForeignKey("AuthorId")]
public virtual AppUser Author { get; set; }
[InverseProperty(nameof(Like.Post))]
public ICollection<Like> Likes { get; set; } = new List<Like>();
[InverseProperty(nameof(Comment.Post))]
public ICollection<Comment> Comments …
Run Code Online (Sandbox Code Playgroud) 我正在创建一个ASP.NET Core API应用程序,当前,当创建一个新项目时,会有一个名为Values的控制器,默认情况下,API会在您运行时打开它.因此,我删除了该控制器并添加了一个名为Intro的新控制器,并在其中添加了一个名为Get的操作.在Startup.cs
文件中,我有以下几行代码:
app.UseMvc(opt =>
{
opt.MapRoute("Default",
"{controller=Intro}/{action=Get}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)
而我的Intro控制器看起来像这样:
[Produces("application/json")]
[Route("api/[controller]")]
[EnableCors("MyCorsPolicy")]
public class IntroController : Controller
{
private readonly ILogger<IntroController> _logger;
public IntroController(ILogger<IntroController> logger)
{
_logger = logger;
}
[HttpGet]
public IActionResult Get()
{
// Partially removed for brevity
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行API时,它默认尝试导航到/api/values
,但由于我删除了值控制器,现在我得到404未找到错误.如果我手动然后导航到/api/intro
,我将获得从Intro控制器内的Get操作提供的结果.如何在API运行时(例如通过Debug-> Start Without Debugging)确保默认情况下从Intro控制器获取Get操作?
我的一个React组件中有一个表单,在调用它的外部组件中,我想向那里的按钮传递引用,以便我也可以使用该按钮提交该表单。
为了更清楚一点,我有以下内容:
import React, { Component } from "react";
import ReactDOM from "react-dom";
class CustomForm extends Component {
render() {
return (
<form onSubmit={alert('Form submitted!')}>
<button type='submit'>Inside Custom</button>
</form>
);
}
}
function App() {
return (
<div>
<CustomForm />
<button>In Root</button>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Run Code Online (Sandbox Code Playgroud)
现在,我可以使用标题为“ Inside Custom”的按钮提交表单,但是我也希望能够使用位于根组件中的标题为“ In Root”的按钮提交表单。有没有办法将引用从该按钮传递到该自定义组件,并在In Root
单击按钮时实际提交表单?
我有一个看起来像这样的代码段:
async function autoScroll(page, maxDate = null) {
await page.evaluate(async () => {
await new Promise(async (resolve, reject) => {
try {
const scrollHeight = document.body.scrollHeight;
let lastScrollTop = 0;
const interval = setInterval(async () => {
window.scrollBy(0, scrollHeight);
const scrollTop = document.documentElement.scrollTop;
let lastDate = null;
if (maxDate) {
const html = new XMLSerializer().serializeToString(document.doctype) + document.documentElement.outerHTML;
await extractDate(html).then((date) => {
lastDate = date;
});
}
if (scrollTop === lastScrollTop ||
(maxDate && lastDate && maxDate.getTime() >= lastDate.getTime())) {
clearInterval(interval); …
Run Code Online (Sandbox Code Playgroud) 我想使用 Puppeteer 在具有滚动条但整个窗口没有滚动条的 div 内滚动。让我们以以下 URL 为例:
您可以在左侧看到评论,并且整个部分都有一个滚动条。快速检查元素显示整个事物被一个具有以下类的 div 包围widget-pane-content scrollable-y
。所以,我尝试做这样的事情:
const scrollable_section = 'div.widget-pane-content.scrollable-y';
await page.evaluate((selector) => {
const scrollableSection = document.querySelector(selector);
scrollableSection.scrollTop = scrollableSection.offsetHeight;
}, scrollable_section);
Run Code Online (Sandbox Code Playgroud)
但是,这没有用。我还注意到,单击空格按钮,如果它集中在评论部分,它也会自动向下滚动。所以,我也尝试做这样的事情:
await page.focus(scrollable_section);
await page.keyboard.press('Space');
Run Code Online (Sandbox Code Playgroud)
但是,这似乎也不起作用。任何想法如何使用 Puppeteer 在 div 内滚动?
我在C中有以下内联汇编:
unsigned long long result;
asm volatile(".byte 15;.byte 49;shlq $32,%%rdx;orq %%rdx,%%rax"
: "=a" (result) :: "%rdx");
return result;
Run Code Online (Sandbox Code Playgroud)
我试着在Rust中重写它:
let result: u64;
unsafe {
asm!(".byte 15\n\t
.byte 49\n\t
shlq 32, rdx\n\t
orq rdx, rax"
: "=a"(result)
:
: "rdx"
: "volatile"
);
}
result
Run Code Online (Sandbox Code Playgroud)
它不承认=a
限制了它给了我一个无效的操作错误rdx
,并rax
在shlq
和orq
指令.在Rust中重写上述C内联汇编的正确方法是什么?
我有一个如下所示的实体(为简洁起见,部分删除,它包括许多其他属性):
public class Tender
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string CreatorId { get; set; }
[ForeignKey("CreatorId")]
public virtual AppUser Creator { get; set; }
public ICollection<TenderCircle> TenderCircles { get; set; } = new List<TenderCircle>();
}
Run Code Online (Sandbox Code Playgroud)
该TenderCircles
属性用于提供与另一个名为 的实体的多对多关系Circle
。TenderCircle
实体看起来像这样:
public class TenderCircle
{
public int TenderId { get; set; }
[ForeignKey("TenderId")]
public Tender Tender { get; set; }
public int CircleId { get; set; }
[ForeignKey("CircleId")]
public Circle Circle { …
Run Code Online (Sandbox Code Playgroud) 我在Rust中做了一些计算数学,并且我有一些大数字,我存储在24个值的数组中.我有将它们转换为字节并返回的函数,但它对u32
值不起作用,而它可以正常工作u64
.代码示例可以在下面找到:
fn main() {
let mut bytes = [0u8; 96]; // since u32 is 4 bytes in my system, 4*24 = 96
let mut j;
let mut k: u32;
let mut num: [u32; 24] = [1335565270, 4203813549, 2020505583, 2839365494, 2315860270, 442833049, 1854500981, 2254414916, 4192631541, 2072826612, 1479410393, 718887683, 1421359821, 733943433, 4073545728, 4141847560, 1761299410, 3068851576, 1582484065, 1882676300, 1565750229, 4185060747, 1883946895, 4146];
println!("original_num: {:?}", num);
for i in 0..96 {
j = i / 4;
k = (i % …
Run Code Online (Sandbox Code Playgroud) 执行该行时,Invoke-WebRequest -Uri https://www.freehaven.net/anonbib/date.html
PowerShell throws抛出WebCmdletResponseException
。我如何获得有关它的更多信息,这可能是什么原因造成的?虽然我可以使用Python成功获取页面的内容,但是在PowerShell中会引发异常。
完全例外:
Run Code Online (Sandbox Code Playgroud)Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send. At line:1 char:1 + Invoke-WebRequest -Uri https://www.freehaven.net/anonbib/date.html + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc eption + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
我正在创建一个 React 应用程序,我有一个如下所示的代码段:
import React, { Component } from 'react';
import { RaisedButton } from 'material-ui';
let isZero = false;
class Button extends Component {
render() {
const { value } = this.props;
isZero = false;
if (value === 0) {
isZero = true;
}
// removed for brevity
}
}
const styles = {
otherStyles: {
minWidth: isZero ? '120px' : '60px',
margin: '5px 5px 5px 0',
lineHeight: isZero ? '120px' : '60px',
},
};
export default Button;
Run Code Online (Sandbox Code Playgroud)
但是,显然条件语句不适用于对象内部,因为当 …
javascript ×3
c# ×2
puppeteer ×2
reactjs ×2
rust ×2
asp.net-core ×1
assembly ×1
async-await ×1
asynchronous ×1
powershell ×1
promise ×1
ssl ×1
tls1.2 ×1