我正在使用 blazor 进行搜索。当我按下输入中的某个键时,它会检查它是否是回车键,如果是,则启动搜索。但是,绑定变量(keywordValue)的值似乎不会更新,直到我连续两次按回车键。如果我第一次按下它,该值不会更新。
<h1>Blogs</h1>
<fieldset>
<label>Keyword Search</label>
<input type="text" @bind="keywordValue" @bind:event="oninput" @onkeypress="KeywordEnterPressed"/>
<button type="submit" @onclick="SearchBlogs">Search</button>
</fieldset>
Run Code Online (Sandbox Code Playgroud)
private string keywordValue { get; set; }
protected async void KeywordEnterPressed(KeyboardEventArgs eventArgs)
{
if (eventArgs.Key == "Enter")
{
await SearchBlogs();
}
}
Run Code Online (Sandbox Code Playgroud)
例如:如果我在输入字段中输入“test”并按 Enter 键,它将运行值为“”的 searchblogs()。当我再次按回车键时,它会运行 searchblogs() ,其值为“test”,就像它应该的那样。
以下是我的代码.当我点击5时,我必须按Enter键5次才能让程序写入该行,而按6则根本不起作用.任何解决方案将不胜感激.
Boolean keepRunning = true;
while (keepRunning = true)
{
if (Console.ReadLine() == "1")
{
Console.WriteLine("Still running");
}
else if (Console.ReadLine() == "2")
{
Console.WriteLine("Still running2");
}
else if (Console.ReadLine() == "3")
{
Console.WriteLine("Still running3");
}
else if (Console.ReadLine() == "4")
{
Console.WriteLine("Still running4");
}
else if (Console.ReadLine() == "5")
{
Console.WriteLine("Still running5");
}
else if (Console.ReadLine() == "6")
{
keepRunning = false;
}
}
Run Code Online (Sandbox Code Playgroud)