Scala Play传递变量以查看不起作用 [英] Scala Play passing variable to view not working

查看:80
本文介绍了Scala Play传递变量以查看不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码可以正常工作:

在控制器中:

Ok(views.html.payment(message,test,x_card_num,x_exp_date,exp_year,exp_month,x_card_code,x_first_name,x_last_name,x_address,x_city,x_state,x_zip,save_account,product_array,x_amount,products_json,auth_net_customer_profile_id,auth_net_payment_profile_id,customer_id))

在视图中:

@(message: String, test: String, x_card_num: String, x_exp_date: String,exp_year: String, exp_month: String, x_card_code: String, x_first_name: String, x_last_name: String, x_address: String, x_city: String, x_state: String, x_zip: String, save_account: String, product_array: Map[String,Map[String,Any]], x_amount: String, products_json: String, auth_net_customer_profile_id: String,auth_net_payment_profile_id: String,customer_id: String)

但是当我尝试向控制器添加另一个变量并像这样查看时:

But when I try to add one more variable to the controller and view like this:

Ok(views.html.payment(message,test,x_card_num,x_exp_date,exp_year,exp_month,x_card_code,x_first_name,x_last_name,x_address,x_city,x_state,x_zip,save_account,product_array,x_amount,products_json,auth_net_customer_profile_id,auth_net_payment_profile_id,customer_id,saved_payments_xml))


@(message: String, test: String, x_card_num: String, x_exp_date: String,exp_year: String, exp_month: String, x_card_code: String, x_first_name: String, x_last_name: String, x_address: String, x_city: String, x_state: String, x_zip: String, save_account: String, product_array: Map[String,Map[String,Any]], x_amount: String, products_json: String, auth_net_customer_profile_id: String,auth_net_payment_profile_id: String,customer_id: String, saved_payments_xml: String)

它给了我这个错误:

missing parameter type 

我在做什么错了?

推荐答案

您可以传递给

There's a limit to the number of parameters you can pass to a template. You've exceeded it when you add another parameter.

这是一个未记录的且相当随意的限制,它是从模板生成代码的结果.可以说这是一个错误,但是我不能修复,因为没有人需要这么多的参数,而有了这么多的参数会使代码的可读性大大降低.

It's an undocumented and fairly arbitrary limit which is the result of how the code generation from a template works. It is arguably a bug, but not one that I would fix since nobody needs this many parameters, and having this many makes code much less readable.

您的最佳解决方案是重构,例如,通过创建一些案例类来表示模型中的Card和Address,然后将其传递给我们.

Your best resolution here is to refactor, for example by creating some case classes to represent Card and Address in your model, and pass those in instead.

这篇关于Scala Play传递变量以查看不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆