我正在使用 Razor Components,对non-static values在list of objects.我有以下代码: @page "/CircularGauge/DefaultFunctionalities"@using Syncfusion.EJ2.RazorComponents.CircularGauge <div class="control-section"> <EjsCircularGauge ID="gauge" Axes="axes"></EjsCircularGauge> </div> @functions { int myInteger = 21; public List<Object> axes { get; set; } = new List<Object> { new { radius = "80%", startAngle = 230, endAngle = 130, majorTicks = new { width = "0px" }, minorTicks = new { width = "0px" }, lineStyle = new { width = 8, color = "#E0E0E0" }, labelStyle = new { font = new { fontFamily = "Roboto", size = "12px", fontWeight = "Regular" }, offset = -5 }, pointers = new List<Object> { new { value = 60, radius = "60%", color = "#757575", pointerWidth = 7, cap = new { radius = 8, color = "#757575", border = new { width = 0 } }, needleTail = new { color = "#757575", length = "25%" } }} } }; }来源:https ://ej2.syncfusion.com/aspnet-core-blazor/CircularGauge/DefaultFunctionalities我在我的代码中使用了一个整数,例如: int myInteger = 21;我想做的是在上面的代码中: pointers = new List<Object> { new { ****value = 60,**** radius = "60%", color = "#757575", pointerWidth = 7, cap = new { radius = 8, color = "#757575", border = new { width = 0 } } }正在将 的值更改value为我的本地整数,但这是不可能的。这就是为什么我一直在寻找解决方案。有没有人对此有所了解?
1 回答
墨色风雨
TA贡献1853条经验 获得超6个赞
您正在使用内联构造函数初始化属性。您无法访问内联构造函数中的实例字段,因为编译器无法确保先完成哪一个。
您应该将 the 定义myInteger
为 static private static int myInteger
。或者您可以在构造函数中建立属性的值,然后您可以在构造函数上使用局部变量。
但是,如果你想定义一个像那个那样的常量变量,我宁愿建议你更多地这样做:
private const int MY_INTEGER = 21;
- 1 回答
- 0 关注
- 77 浏览
添加回答
举报
0/150
提交
取消