如何在Caveman中获取多个查询参数

时间:2017-11-16 08:14:32

标签: common-lisp hunchentoot caveman2

我的代码在REPL中运行良好,但它在我的Web应用程序中没有得到第二个值。

例如(?vehicle=bike&vehicle=car)

我尝试了什么

当我做的时候

  • CL-使用者> (setf |vehicle| '(a b c)
  • CL-使用者> (let ((|vehicle| (multival-plist:getf-all `(:|vehicle| ,|vehicle|) :|vehicle|))) (print (alexandria:flatten (list :vehicle |vehicle|))))

产生所需的输出(:VEHICLE A B C)

但是当我提交表格时

<form action="/checkbox">
    <input type="checkbox" name="vehicle" value="bike"> I have a bike<br>
    <input type="checkbox" name="vehicle" value="car"> I have a car<br>
    <input type="submit" value="Submit">
</form> 

到我的路线

@route GET "/checkbox"
(lambda (&key |vehicle|)
  (let ((|vehicle| (multival-plist:getf-all `(:|vehicle| ,|vehicle|) :|vehicle|)))
    (format nil "~a" (list :vehicle (alexandria:flatten |vehicle|)))))

实际上我将结果呈现给djula模板,但是为了测试我改为使用format

<ul>
    {% for a in vehicle %}
        <li>{{ a }}</li>
    {% endfor %}
</ul>

仅导致(VEHICLE (bike)),其中有两个已经过检查,结果为

  • 自行车

我期待发生什么

输出

  • 自行车

我将在我的应用中使用16个复选框,这将导致非常长的链接,任何建议使链接缩短。

PS:我使用的是Hunchentoot服务器和Caveman2 Web框架。

1 个答案:

答案 0 :(得分:0)

在html中将name=vehicle更改为name=vehicle[],当两者都被检查为("bike" "car")的值时,caveman2会将其解析为列表vehicle的值列表。< / p>