2016-11-21 12 views
2

イベントに含まれるデータをテストするために、time exampleに基づいて簡単なプログラムを作成しました。 JSONを値にデコードし、JSONにエンコードしてSVGテキスト要素に表示します。私が得るのは{"isTrusted":true}だけです。Elm JSONイベントでisTrusted以外のデータがありません

なぜですか。別のイベントデータを取得するにはどうすればよいですか?私は、Firefox 49とonline compilerを使用しています:

import Html exposing (Html) 
import Svg exposing (..) 
import Svg.Attributes exposing (..) 
import Svg.Events exposing(on) 
import Json.Decode as Json 
import Json.Encode exposing (encode) 

main = 
    Html.program 
    { init = init 
    , view = view 
    , update = update 
    , subscriptions = subscriptions 
    } 

-- MODEL 
type alias Model = String 

init : (Model, Cmd Msg) 
init = 
    ("No event", Cmd.none) 


-- UPDATE 
type Msg 
    = Event String 

update : Msg -> Model -> (Model, Cmd Msg) 
update msg model = 
    case msg of 
    Event event -> 
     (event, Cmd.none) 


subscriptions model = Sub.none 


stringifyEvent: Json.Encode.Value -> Msg 
stringifyEvent x = 
    Event (encode 2 x) 

-- VIEW 

view : Model -> Svg Msg 
view model = 
    svg [ viewBox "0 0 300 300", width "300px", on "mousedown" (Json.map stringifyEvent Json.value) ] [ 
     text_ [x "0", y "30"] [text model] 
    ] 

私はそれがすべての属性で動作し、コンソールに

svgElement.addEventListener('click', function(e) {console.log(e)}) 

をしようとします。

答えて

3

あなたの目標を達成する方法がわかりません。 しかし、私はあなたに説明したように答えてくれます。

あなたがソースコードを見れば、あなたはエルムランタイムがStringValueを変換するための JSON.stringify()を使用していることを見つけることができます。あなたがクリックしたときに svgElement.addEventListener('click', function(e) {console.log(JSON.stringify(e))}) はあなたに{"isTrusted":true}を与える

そして、何を推測... ...

+1

追加の注記:http://stackoverflow.com/a/11547845/1238847 – Tosh

関連する問題