我有一个看起来像这样的数组.
[{"EntryId"=>"2", "Field1"=>"National Life Group","DateCreated"=>"2010-07-30 11:00:14", "CreatedBy"=>"tristanoneil"},
{"EntryId"=>"3", "Field1"=>"Barton Golf Club", "DateCreated"=>"2010-07-30 11:11:20", "CreatedBy"=>"public"},
{"EntryId"=>"4", "Field1"=>"PP&D Brochure Distribution", "DateCreated"=>"2010-07-30 11:11:20", "CreatedBy"=>"public"},
{"EntryId"=>"5", "Field1"=>"Prime Renovation Group, DreamMaker Bath & Kitchen", "DateCreated"=>"2010-07-30 11:11:21", "CreatedBy"=>"public"}
]
Run Code Online (Sandbox Code Playgroud)
我将如何迭代遍历此数组,以便我可以指定要打印的字段并获取值,因此我可以执行类似的操作.
puts EntryId.value
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Elixir中的Google Maps地理编码API,虽然我对该语言有点新,因此使用嵌套数据结构正在逃避我.
我正在使用HTTPotion从地理编码端点获取JSON,并使用JSEX将其解析为Elixir数据结构(一系列嵌套列表和元组).
defmodule Geocode do
def fetch do
HTTPotion.start
result = HTTPotion.get "http://maps.googleapis.com/maps/api/geocode/json?address=Fairfax,%20Vermont&sensor=false"
json = JSEX.decode result.body
end
end
Run Code Online (Sandbox Code Playgroud)
以下内容现已分配给json.
{:ok, [{"results", [[{"address_components", [[{"long_name", "Fairfax"}, {"short_name", "Fairfax"}, {"types", ["locality", "political"]}], [{"long_name", "Franklin"}, {"short_name", "Franklin"}, {"types", ["administrative_area_level_2", "political"]}], [{"long_name", "Vermont"}, {"short_name", "VT"}, {"types", ["administrative_area_level_1", "political"]}], [{"long_name", "United States"}, {"short_name", "US"}, {"types", ["country", "political"]}]]}, {"formatted_address", "Fairfax, VT, USA"}, {"geometry", [{"bounds", [{"northeast", [{"lat", 44.772892}, {"lng", -72.92268890000001}]}, {"southwest", [{"lat", 44.6330508}, {"lng", -73.08477409999999}]}]}, {"location", [{"lat", 44.6654963}, {"lng", -73.01032}]}, {"location_type", "APPROXIMATE"}, {"viewport", [{"northeast", [{"lat", 44.772892}, …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用has_many:through方法建立多对多关系,然后使用多选字段来设置关系.我正在学习本教程:
http://asciicasts.com/episodes/185-formtastic-part-2
但是由于某种原因,表单会显示一个奇怪的十六进制数字并且它会更改每个页面刷新,我不确定我做错了什么.下面是我的模型/视图代码.
company.rb
has_many :classifications
has_many :sics, :through => :classifications
Run Code Online (Sandbox Code Playgroud)
sic.rb
has_many :classifications
has_many :companies, :through => :classifications
Run Code Online (Sandbox Code Playgroud)
classification.rb
belongs_to :company
belongs_to :sic
Run Code Online (Sandbox Code Playgroud)
_form.html.erb
<% semantic_form_for @company do |f| %>
<% f.inputs do %>
<%= f.input :company %>
<%= f.input :sics %>
<% end %>
<%= f.buttons %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
此外,表格看起来像是显示该字段的正确条目数,但显然没有显示该关系的正确名称.
我试图以编程方式添加几个从TextViews
一个延伸到一个的Tiles RelativeLayout
.
我的代码如下.
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
for (int i = 0; i < characters.length; i++) {
Tile tile = new Tile(this);
tile.setText(Character.toString(characters[i]));
tile.setId(i);
if (i != 0) {
params.addRule(RelativeLayout.RIGHT_OF, i - 1);
}
_display.addView(tile, params);
}
Run Code Online (Sandbox Code Playgroud)
所以我正在创建一个新的LayoutParams
被调用实例类,params
并添加一个规则来将每个tile对齐到前一个tile的右侧.当我运行应用程序时,看起来瓷砖彼此重叠.有什么建议?