开发者

Refer to a field (Model.field) with a variable (@field)

开发者 https://www.devze.com 2023-04-04 00:15 出处:网络
I have a variable called @field that is set to 开发者_如何学Goequal a field name, like @field = \"city\".

I have a variable called @field that is set to 开发者_如何学Goequal a field name, like @field = "city".

How can I use that variable to access Model.city? Literally, how can I get Model.@field to work?


Using send. Model.send( @field )

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号