简体   繁体   English

如何在WebSharper UI中处理选择选项的onchange。

[英]How can I handle onchange for a select option in WebSharper UI.Next

I am trying to display a different SPA view based on the option selected from Doc.Select. 我试图根据从Doc.Select中选择的选项显示不同的SPA视图。

I would like to handle onchange events using WebSharper UI.Next. 我想使用WebSharper UI.Next处理onchange事件。 I have searched around for some information and have seen on which can be set in the attributes of an Elt , like so: 找遍了周围的一些信息,并看到on它可以在属性设置Elt ,就像这样:

spanAttr [on.click (fun el ev -> ())] [text "some span"]

found here: http://www.websharper.com/question/81410/event-handlers-for-ui-next-elt-objects 在此处找到: http : //www.websharper.com/question/81410/event-handlers-for-ui-next-elt-objects

However, I am quite unsure of how to handle a change on Doc.Select using the tools available in UI.Next. 但是,我不确定如何使用Doc.Select中提供的工具来处理Doc.Select上的更改。

I have the following: 我有以下几点:

let rv = Var.Create "1"
Doc.Select [  ] (fun _ -> "") [ "1"; "2"; "3" ] rv

I am not sure how to get access to onchange events so I can use the router to redirect to a different SPA view. 我不确定如何访问onchange事件,因此我可以使用路由器重定向到其他SPA视图。

What is the convention for doing something like changing a view based on the dropdown selection? 根据下拉选择进行诸如更改视图之类的约定是什么?

You don't need to handle onchange yourself. 您无需自己处理onchange If you use Doc.Select the corresponding Var will be updated every time the dropdown changes. 如果您使用Doc.Select ,则每次下拉列表更改时,相应的Var都会更新。 You can just do something like: 您可以执行以下操作:

rv.View.Doc(function
    | "1" -> text "page 1"
    | "2" -> text "page 2"
    | "3" -> text "page 3"
    | _ -> failwith "Should never happen")

and embed that into your main Doc that gets rendered. 并将其嵌入到要呈现的主Doc中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM