我有标志解码器默认值.
flagsDecoder : Decode.Decoder Params
flagsDecoder =
Decode.map8 Params
(Decode.field "field1" (Decode.string) |> (Decode.withDefault) "1")
(Decode.field "field2" (Decode.string) |> (Decode.withDefault) "2")
(Decode.field "field3" (Decode.string) |> (Decode.withDefault) "3")
(Decode.field "field4" (Decode.string) |> (Decode.withDefault) "4)
(Decode.field "field5" (Decode.string) |> (Decode.withDefault) "5")
(Decode.field "field6" (Decode.int) |> (Decode.withDefault) 6)
(Decode.field "field7" (Decode.string) |> (Decode.withDefault) "7")
(Decode.field "field8" (Decode.string) |> (Decode.withDefault) "8")
Run Code Online (Sandbox Code Playgroud)
我该如何添加更多字段?我有一个包含10个字段的JSON对象.
我有这样简单的url builder:
prepareUrl : Params -> String
prepareUrl params =
Url.crossOrigin "http://someapi.com/"
["posts"]
[
, Url.string "currency" params.currency
, Url.string "members[0][birthday]" "12.12.1989"
]
Run Code Online (Sandbox Code Playgroud)
当我收到像memberCount 2或3之类的param时,我需要在请求中"克隆"成员[],如下所示:
params.membersCount = 3
prepareUrl : Params -> String
prepareUrl params =
Url.crossOrigin "http://someapi.com/"
["posts"]
[
, Url.string "currency" params.currency
, Url.string "members[0][birthday]" "12.12.1989"
, Url.string "members[1][birthday]" "12.12.1989"
, Url.string "members[2][birthday]" "12.12.1989"
]
Run Code Online (Sandbox Code Playgroud)
日期字符串本身可以保持不变,也没关系.我怎样才能做到这一点?
如何一次更新模型中的两个字段?现在我请求给我一个别名{price:Float,productId:Int}我需要更新模型中的两个字段,如model.price和model.productId
我正在寻找类似的东西,但它不起作用(ofc)
case maybeProduct of
Just product ->
( { model | price = product.price &&
model | productId = product.productId}
, Cmd.none
)
Nothing ->
( model
, Cmd.none
)
Run Code Online (Sandbox Code Playgroud)
我找到了一些信息,其中建议我可以创建两个函数(模型 - >产品 - >模型),并执行以下操作:
setPrice : Model -> Product -> Model
setPrice model product =
{ model | price = product.price }
setProductId : Model -> Product -> Model
setProductId model product =
{ model | companyId = product.productId }
Just product ->
let
newModel =
product
|> …Run Code Online (Sandbox Code Playgroud) 我有一个史诗,它捕获每个获取状态的调度(只是来自状态的项目,例如 state.process:{ status: fail, success, inWork},而不是像 200、500 等的请求状态)。当状态 == 成功(通过从状态获取状态)时,我需要调度另一个动作,如 SET_STATUS_SUCCESS
const getStatus = (action, state) =>
action.pipe(
ofType(GET_STATUS),
withLatestFrom(state),
mergeMap(([action, state]) => {
const { status } = state.api.process; //here is what i need, there is no problem with status.
if (status === "success") {
return mapTo(SET_STATUS_SUCCESS) //got nothing and error.
}
})
);
Run Code Online (Sandbox Code Playgroud)
现在我收到错误:
未捕获的类型错误:您提供了 'function (source) { return source.lift(new MapToOperator(value)); }' 需要流的地方。您可以提供 Observable、Promise、Array 或 Iterable。在 subscribeTo (subscribeTo.js:41)
我该怎么办?我尝试只返回 setStatusSuccess 操作,但它也不起作用。