我正在使用现有的Rails应用程序,其中导航必须继续在后端构建(由于复杂性和时间限制).预期的结果是使用Elm生成一些页面,一些使用Rails,不使用哈希,也不使用整页重新加载(至少对于Elm页面).导航的简化版本如下所示:
<nav>
<a href="rails-page-1">...
<a href="rails-page-2">...
<a href="elm-page-1">...
<a href="elm-page-2">...
</nav>
<div id="elm-container"></div>
Run Code Online (Sandbox Code Playgroud)
我已经尝试过使用Elm导航软件包和elm-route-url,可能与后者接近,除非我从根本上误解了软件包的功能.
有没有办法实现这个目标?我已经使用哈希标签工作,但没有它们就没有运气.
我通过端口将一组对象传递到我的 Elm 应用程序中。数组中对象之一的示例是:
{
FullName: 'Foo Bar',
Location: 'Here'
}
Run Code Online (Sandbox Code Playgroud)
如您所见,对象中的键以大写开头,因此我需要在 Elm 中对它们进行解码。在我的榆树代码,我有一个type为Person
type alias Person =
{ fullName : String
, location : String
}
Run Code Online (Sandbox Code Playgroud)
和港口:
port getPeople : (List Json.Decode.Value -> msg) -> Sub msg
Run Code Online (Sandbox Code Playgroud)
最后我有一个解码器(我使用Elm Decode Pipeline)来将数据解析为Person类型。
peopleDecoder : Decoder Person
peopleDecoder =
decode Person
|> required "FullName" string
|> required "Location" string
Run Code Online (Sandbox Code Playgroud)
我的问题是如何将传入端口数据映射到Person类型中?我知道我可以在 JS 中做到这一点,但我宁愿在我的 Elm 代码中做到这一点。
我想知道Elm中元素的属性html,例如她的坐标.我正在尝试使用Json.Decode.
我是榆树的新人,这是出于学习目的.
这是一个简单的代码,我使用的是Elm 0.18:
module Stamps exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
type alias Model =
{}
type Msg
= NoOp
| Clicking
model : Model
model =
{}
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
NoOp ->
( model, Cmd.none )
Clicking ->
let
_ =
Debug.log "msg1" model
in
( model, Cmd.none )
view : Model -> Html Msg …Run Code Online (Sandbox Code Playgroud)