Ruby页面,循环赋值方法(类似java EL表达式赋值)
------------前台代码---------------
<% @form_hash.each_with_index do |f,index| %> <% item = f[:item] %> <tr id="tr<%= index %>" data-attr="datatr"> <td><input type="text" class="dateTimepickerH start_datetime" name="" value="<%= item["CYRQ"] %>"></td> <td><input class="input-sm" id="CYSJJG0" name="CYSJJG0" type="text" value="<%= item["CYSJJG"] %>"></td> <td><input class="input-sm" id="POLLUTANTTYPE0" name="POLLUTANTTYPE0" type="text" value="<%= item["HPA"] %>"></td> <td><input class="input-sm" id="LJLL0" name="LJLL0" type="text" value="<%= item["LJLL"] %>"></td> <td><input class="input-sm" id="LMBH0" name="LMBH0" type="text" value="<%= item["LMBH"] %>"></td> <td><input class="input-sm" id="CYQMZ0" name="CYQMZ0" type="text" value="<%= item["CYQMZ"] %>"></td> <td><input class="input-sm" id="CYHMZ0" name="CYHMZ0" type="text" value="<%= item["CYHMZ"] %>"></td> <td><input class="input-sm" id="LMZZ0" name="LMZZ0" type="text" value="<%= item["LMZZ"] %>"></td> <td><input class="input-sm" id="KLWND0" name="KLWND0" type="text" value="<%= item["KLWND"] %>"></td> <td><input tvbox="true" readonly="readonly" style="width:85px;" class="form-control" id="CYRID0_Text" name="CYRID0_Text" type="text" validator="required" value="<%= item["JLRID_Text"] %>" original-title=""></td> <td><input id="CZRID0" name="CZRID0" style="width:65px;" type="text" value="<%= item["CZRID"] %>"></td> <td> <input class="input-sm" id="TQZK0" name="TQZK0" type="text" value="<%= item["TQZK"] %>"> <input type="hidden" id="MCDETAILID_0" name="MCDETAILID_0" value=""> </td> <td> <a class="btn btn-default btn-sm" href="javascript:void(0);" target="_self"> <i class="icon-file" sampling_record="sampling_record_<%= index + 1 %>"></i>查看 </a> </td> </tr> <% end %>
---------------------后台封装代码-------------------
#返回 颗粒物 首页 的结果 def get_values_klw form_module=FFormModule.select("id","code").where(:code => ['sampling_record_1','sampling_record_2','sampling_record_3','sampling_record_4','sampling_record_5', 'sampling_record_6','sampling_record_7','sampling_record_8','sampling_record_9','sampling_record_10']) #render json:{ item_data: do_hash(form_module,params[:id]) } do_hash(form_module,params[:id]) end def do_hash(form_module,form_id) @form_hash = [] form_module.each_with_index do |mod,index| f_field_values=FFieldValue.where(:d_task_form_id => form_id, :f_form_module_id => mod.id) @file_hash = {} f_field_values.map{|x| @file_hash[x.field_title] = x.field_value } @form_hash << {item_index: mod.code[-2,2],item: @file_hash} end return @form_hash.sort{|x,y| x[:item_code] <=> y[:item_code] } end