我正在玩 Blazor 中的自定义模板,我试图找到一种方法来双向绑定 aCascadingValue或实现类似的东西。现在我有以下模板。
@if (PopupVisible)
{
<DxPopup>
<HeaderTemplate>
<h4 class="modal-title">@HeaderText</h4>
<button type="button" class="close" @onclick="@UpdatePopupVisible">×</button>
</HeaderTemplate>
<ChildContent>
<div class="modal-body">
<div class="container-fluid">
@bodyContent
</div>
</div>
<div class="modal-footer">
@footerContent
<button class="btn btn-secondary" @onclick="UpdatePopupVisible">Cancel</button>
</div>
</ChildContent>
</DxPopup>
}
@code {
[CascadingParameter] public bool PopupVisible { get; set; }
[CascadingParameter] public EventCallback<bool> PopupVisibleChanged { get; set; }
[Parameter] public RenderFragment HeaderText { get; set; }
[Parameter] public RenderFragment footerContent { get; set; }
[Parameter] public RenderFragment bodyContent { get; set; }
private …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何使用自定义版本的 fold(基本上用作 foldl)在 Haskell 中创建自定义解压缩函数,但我被卡住了。我可以得到它
unzip' :: [(a,b)] -> ([a],[b])
unzip' = fold (\x->([x!!0],[x!!1])) ([],[])
Run Code Online (Sandbox Code Playgroud)
但这会出错:
• Couldn't match expected type ‘[a]’
with actual type ‘(Integer, Integer)’
• In the first argument of ‘tail’, namely ‘(1, 2)’
In the expression: tail (1, 2)
In an equation for ‘it’: it = tail (1, 2)
• Relevant bindings include
it :: [a] (bound at <interactive>:114:1)
Run Code Online (Sandbox Code Playgroud)
据我所知,x是,(1,2)但我不确定如何将其进一步拆分为 1 和 2。这是我正在使用的 fold 函数:
fold :: (a -> b -> b) …Run Code Online (Sandbox Code Playgroud)