我有带有html标记的字符串,我想从它中创建这样的字符串:
Doc.FromHtm "<div><p>.....</p>.....</div>"据我所知,现在这是不可能的。好的,不可能准确地缝制的,我试着用jquery粗略地钉上钉子:
JQuery.JQuery.Of( "." + class'name ).First().Html(html'content)但是要调用这段代码,我需要为Doc元素指定一个事件处理程序。但是它没有在UI.Next中实现。我尝试异步跟踪具有给定CSS类的模型的更改:
let inbox'post'after'render = MailboxProcessor.Start(fun agent ->
let rec loop (ids'contents : Map<int,string>) : Async<unit> = async {
// try to recive event with new portion of data
let! new'ids'contents = agent.TryReceive 100
// calculate the state of the agent
let ids'contents =
// merge Map's
( match new'ids'contents with
| None -> ids'contents
| Some (new'ids'contents) ->
new'ids'contents @ (Map.toList ids'contents)
|> Map.ofList )
|> Map.filter( fun id content ->
// calculate CSS class name
let class'name = post'text'view'class'name id
// change it's contents of html
JQuery.JQuery.Of( "." + class'name ).First().Html(content).Size() = 0)
// accept the state of the agent
return! loop ids'contents }
loop Map.empty ) 然后,例如,对于一个元素:
inbox'post'after'render.Post [id, content]但是它太难了,不可靠,而且没有真正的工作。如果可能的话,请给我一个解决问题的方法。提前感谢!
发布于 2015-11-01 17:09:56
如果有人需要在WebSharper中使用服务器上的静态HTML (我需要向WebSharper生成的HTML页面添加一些javascript),就会有相当新的Doc.Verbatim可用,例如
let Main ctx action title body =
Content.Page(
MainTemplate.Doc(
title = title,
menubar = MenuBar ctx action,
body = body,
my_scripts = [ Doc.Verbatim JavaScript.Content ]
)
)发布于 2015-06-29 12:41:13
已经在https://github.com/intellifactory/websharper.ui.next/issues/22上回答了这个问题,但是在这里复制了我的答案:
如果您只想从静态html创建一个UI.Next文档,您可以执行以下操作:
let htmlElem = JQuery.JQuery.Of("<div>hello</div>").Get(0)
let doc = Doc.Static (htmlElem :?> _)这不是很好,但应该有效,我认为目前没有更好的方法。或者您可以使用模板,但这还没有文档化,我不确定它是否适合您的用例。
显然,如果您想动态地更改呈现的元素,可以将其变为Var,并与Doc.Static一起使用Doc.EmbedView。
https://stackoverflow.com/questions/31045593
复制相似问题