基于行为的动态元素在threepenny-gui中 [英] Dynamic Elements based on Behaviour in threepenny-gui

查看:134
本文介绍了基于行为的动态元素在threepenny-gui中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单地说,我正在寻找一种方法来显示行为(UI元素)



我的实际使用情况是显示一个可以过滤的表格。所以我有一个函数 tableElement :: String - > UI元素(作为过滤条件的 String 参数)和输入字段 filterElement :: Element

  bFilter<  -  stepper(valueChange filterElement) 
displaySomehow(fmap tableElement bFilter)

这也是在Elm中完成的方式。



到目前为止我发现的最接近的东西是使用汇儿童,但只适用于 [元素] ,而不是 [UI元素] 。此外,我必须使用一个虚拟元素作为父母或与剩下的孩子一起玩耍。



用三个penny-gui来实现这样的事情最好的方法是什么?

解决方案

(作者在这里)

c> UI元素表示一个 action ,执行时可以创建 new 元素。您将不得不执行后者的操作。不幸的是,目前没有办法在FRP风格中完全实现这一点,只要过滤器发生变化,您将不得不求助于 onChanges 组合器重新创建表。在那里,您可以使用 set children



示例:

  onChanges bFilter $ \s  - > do 
el< - tableElement s
myTable#sink children [el]

Bartab.hs CRUD.hs 的例子可能与您的情况有关。


To put it simple, I am looking for a way to display a Behaviour (UI Element).

My actual use-case is displaying a table, which can be filtered. So I have a function tableElement :: String -> UI Element (the String parameter being the filter condition) and an input field filterElement :: Element, which represents the filter. The most natural way for me to combine these would be something like this:

bFilter <- stepper "" (valueChange filterElement)
displaySomehow (fmap tableElement bFilter)

This is also the way it is done in Elm.

The closest thing I have found so far is using sink children, but that works only with [Element] and not with [UI Element]. Additionally I have to use a dummy element as parent or fiddle around with the remaining children.

What would be the best way to to implement something like this with threepenny-gui?

解决方案

(Author here)

Note that UI Element represents an action that, when executed, may create a new Element. You will have to execute the action to do the latter. Unfortunately, there is currently no way to do that completely within the FRP style, you will have to resort to the onChanges combinator to create the table anew whenever the filter changes. There, you can use set children.

Example:

onChanges bFilter $ \s -> do
    el <- tableElement s
    myTable # sink children [el]

The Bartab.hs and CRUD.hs examples may be relevant for your situation.

这篇关于基于行为的动态元素在threepenny-gui中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆