我正在学习 Blazor 技术。我在 VS 2019 中启动了一个默认的增量项目,并且我已经使用 confirm() 和 alert 修改了 Decrement 的代码,但它不起作用。
@page "/counter"
<h1>Counter</h1>
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Increment</button>
<button class="btn btn-primary btn-danger" onclick="if (confirm('Are you sure to Decrement')) { @DecrementCount() }">Decrement</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
private void DecrementCount()
{
currentCount--;
// alert('Operation Successfully executed')
}
}
Run Code Online (Sandbox Code Playgroud)
在我的代码片段中,confirm() 函数运行良好,但我想调用 Decrement 函数不起作用构建失败。我想在我的函数中添加一条成功消息。请提供任何选项,而不是使用 confirm(),alert() 函数。
我正在使用 C# 12。在 C# 12 中我可以使用主构造函数:
实施1:
public class Calculation(int a,int b)
{
public int Addition() => a + b;
public int Subtraction() => a - b;
}
Run Code Online (Sandbox Code Playgroud)
实施2:
public class Calculation(int a,int b)
{
private int _a { get; init; } = a;
private int _b { get; init; } = b;
public int Addition() => _a + _b;
public int Subtraction() => _a - _b;
}
Run Code Online (Sandbox Code Playgroud)
当我像这样调用这个方法时:
console.WriteLine(new Calculation(10,25).Addition());
Run Code Online (Sandbox Code Playgroud)
两种实现都工作正常,所以我想知道使用较长的实现 2 相对于较短的实现 1 是否有任何优势。
我的网络服务代码是
[WebMethod]
public List<test> GetMachineData_List(string prefix, int person_id)
{
using (var db = new TestDB())
{
List<test> list = db.Fetch<test>("select id,name from machine_data_collection mc where mc.id=@0 and name like '%" + prefix + "%'", person_id);
return list.ToList();
}
}
Run Code Online (Sandbox Code Playgroud)
我的 jquery Ajax 调用是
$("#textbx").autocomplete(
{
source: function (request, response) {
$.ajax({
url: 'http://localhost:4787/ws/webservice.asmx/GetMachineData_List',
data: { prefix: request.term.toString() ,person_id:1},
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
var jsonArray;
try {
jsonArray = $.parseJSON(data.d); // using jQuery
} …
Run Code Online (Sandbox Code Playgroud) 我需要约.每个日期30个百分点的数据.
id name datecol
-----------------------
1 A 2016-11-11
2 B 2016-11-11
3 C 2016-11-11
4 D 2016-11-11
5 E 2016-11-11
6 F 2016-11-11
7 G 2016-11-11
8 H 2016-11-11
9 I 2016-11-11
10 J 2016-11-11
11 A1 2016-11-12
12 B1 2016-11-12
13 C1 2016-11-12
14 D1 2016-11-13
15 E1 2016-11-13
16 F1 2016-11-14
17 G1 2016-11-14
18 H1 2016-11-14
19 I1 2016-11-14
20 J1 2016-11-14
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我有
2016-11-11 10行2016-11-12
2016-11-13
2行2016-11-14
5行
我需要这样的约.每个日期的顶行占30%,
id name datecol
-----------------------
1 A 2016-11-11
2 …
Run Code Online (Sandbox Code Playgroud) c# ×3
.net-8.0 ×1
ajax ×1
asp.net ×1
asp.net-core ×1
blazor ×1
c#-12.0 ×1
jquery ×1
sql ×1
sql-server ×1
web-services ×1
webassembly ×1