我有反应式 Var 变量 varDone 和 Doc.Checkbox 来表示其名为 cbDoc 的表示。更改 varDone 的值后,我需要调用我的函数。为此,我编写了以下伪代码所示的代码:
open WebSharper
open WebSharper.UI.Next
open WebSharper.UI.Next.Html
open WebSharper.UI.Next.Notation
// declaring reactive bool variable
let varDone = Var.Create false
(* something else *)
// creting Doc-representation of my model
let renderModel model =
// declaring its representation Doc element
let cbDone = Div0 [ Doc.CheckBox [ "type" ==> "checkbox" ] varDone ]
let result'doc = // a Doc-representation, that contains cbDone
let my'handler() : unit -> unit = // a function that should be called when changing the value of varDone
// add an event handler for the element cbDone changes
(Doc.AsPagelet cbDone).Body.AddEventListener( "change", my'handler, false )
result'doc
但不幸的是,复选框更改时没有发生任何事件。问题是,我做错了什么,是否有另一种方法来响应 varDone 变量值的变化?
UPD
最可悲的是,带有复选框的元素甚至没有我的事件处理程序。这在浏览器中调试时很明显。