-1

在java脚本中,我可以定义一个变量。

var topping = data.getValue(selectedItem.row, 0);

然后,我想像这样使用顶部值:

console.log(<%= @ecs.where(status:topping).count %>);

显然,它不能工作,因为它不会找到浇头在哪里。所以我的问题是我们应该如何使用 <%= %> 中的脚本参数。

4

1 回答 1

2

you probably confuse between server side script and client side script. <%= %> is server side script. javascript is client side script. When rendering a page, Ruby on Rails executes the server side script first, then send the response to your browser, YOUR BROWSER executes the client side script later, so you can't use client side variables in <%= %>.

If you want to get the result dynamically based on client side variables. Use AJAX. Send the parameter to the server, and get the response with javascript. It's a big picture. See tutorials below(not sure it will work) or start with a rails book(Agile Web Development with Rails) or google it.

rails ajax tutorials

于 2013-08-13T03:43:37.327 回答