我希望从FFI函数定义返回对Javascript对象的引用,以便以后能够操作该对象:
import Data.Aeson
import Foreign.JavaScript (JSObject, NewJSObject, unsafeCreateJSObject)
import Foreign.RemotePtr (RemotePtr)
import Graphics.UI.Threepenny.Core hiding (text)
mkJSObject :: JSFunction NewJSObject -> UI JSObject
mkJSObject f = askWindow >>= liftIO . flip unsafeCreateJSObject f
polyLine :: [[Double]] -> Value -> UI JSObject
polyLine points = mkJSObject . f points
where
f :: [[Double]] -> Value -> JSFunction NewJSObject
f = ffi "L.polyline(%1, %2).addTo(map)"
但底层的Javascript窗口似乎无法公开访问。是否有另一种方法来创建对Javascript对象的引用?
答案 0 :(得分:1)
它实际上要简单得多:只需从JSFunction返回一个JSObject,它就会被正确编组:
animalDef