0

我如何才能<%= "@obj#{count}" %>在 DOM 中实际显示变量值而不是 @obj0、@obj1 等

我有需要显示的变量@obj0、@obj1、@obj2 等

4

2 回答 2

2

A couple of ways.

First, the most correct (IMHO) is to put all your vars to an array and index that.

 arr = [@obj0, @obj1, @obj2]

 <%= arr[count] %>

Another option is to use eval. Avoid this (unless you really know what you're doing).

<%= eval("obj#{count}") %>
于 2012-05-26T23:04:24.597 回答
0

我不太确定你想要什么,但我想你想要

<%= @obj.count %>
于 2012-05-26T22:53:38.660 回答