在 C# 中:
var cities = clients.Select(c =>
new {
DisplayText = c.CityName,
Value = c.CityId
});
return Json(new { Result = "OK", Options = cities });
如何在 Rails 中执行此操作?
目标json:
{
"Result" : "OK",
"Options": [
{ "DisplayText" : "clientName1", "Value" : 1},
{ "DisplayText" : "clientName2", "Value" : 2},
]
}