【问题标题】:Forms for nested structures in yesodyesod 中嵌套结构的形式
【发布时间】:2012-02-12 19:16:28
【问题描述】:

我有以下几种:

data Cheese = Cheddar Int | Edam String String | Cottage String Int

data Meal = Meal {
      nameOfMeal :: String,
      ... other generic fields
      cheese :: Cheese
}

目前我的表单如下所示:

cheddarForm = renderTable $ construct 
             <$> areq textField "Name of meal" Nothing
             <*> areq intField "Cheddar fat" Nothing
      where 
          construct name fat = Meal name (Cheddar fat)

我目前对以下事实感到非常满意,即每种“奶酪”都需要一种形式(尽管我当然不介意使用动态形式..)。但是,我真的很想摆脱以各种形式重复“用餐名称”。我可以以某种方式组合这些表格,还是我最终必须使用 Monadic 表格?

【问题讨论】:

    标签: haskell yesod


    【解决方案1】:

    你就不能绕路

    conWithNOM ctr = ctr
        <$> areq textField "Name of meal" Nothing
    

    并针对您的其他表单字段调用它?

    cheddarForm = renderTable $ conWithNOM construct
        <*> areq intField "Cheddar fat" Nothing
      where 
          construct name fat = Meal name (Cheddar fat)
    

    【讨论】:

      猜你喜欢
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多