我正在使用 Razor Components,對(duì)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我在我的代碼中使用了一個(gè)整數(shù),例如: 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為我的本地整數(shù),但這是不可能的。這就是為什么我一直在尋找解決方案。有沒有人對(duì)此有所了解?
1 回答

墨色風(fēng)雨
TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超6個(gè)贊
您正在使用內(nèi)聯(lián)構(gòu)造函數(shù)初始化屬性。您無法訪問內(nèi)聯(lián)構(gòu)造函數(shù)中的實(shí)例字段,因?yàn)榫幾g器無法確保先完成哪一個(gè)。
您應(yīng)該將 the 定義myInteger
為 static private static int myInteger
?;蛘吣梢栽跇?gòu)造函數(shù)中建立屬性的值,然后您可以在構(gòu)造函數(shù)上使用局部變量。
但是,如果你想定義一個(gè)像那個(gè)那樣的常量變量,我寧愿建議你更多地這樣做:
private const int MY_INTEGER = 21;
- 1 回答
- 0 關(guān)注
- 115 瀏覽
添加回答
舉報(bào)
0/150
提交
取消