我正在开发 ROR 应用程序,我首先从视图中的 ruby 变量生成表。变量是这样的:
h=[{"folder"=>"test3", "weight"=>"100.0", "stocks"=>[{"id"=>"stock id3", "name"=>"Indian Oil Corporation Ltd.", "weight"=>"55.8"}, {"id"=>"stock id4", "name"=>"Power Finance Corporation Ltd.", "weight"=>"44.2"}]},{"folder"=>"test", "weight"=>"100.0", "stocks"=>[{"id"=>"stock id3", "name"=>"Indian Oil Corporation Ltd.", "weight"=>"55.8"}, {"id"=>"stock id4", "name"=>"Power Finance Corporation Ltd.", "weight"=>"44.2"}]},{"folder"=>"test2", "weight"=>"100.0", "stocks"=>[{"id"=>"stock id3", "name"=>"Indian Oil Corporation Ltd.", "weight"=>"55.8"}, {"id"=>"stock id4", "name"=>"Power Finance Corporation Ltd.", "weight"=>"44.2"}]}]
现在这是生成表的方式:
<h1 align="center"> Current Portfolio </h1>
<table id="portfolios" width="500" border="1" align="center" height="300">
<thead class="colHeaders">
<tr><th class="weight" bgcolor="#999999"><h4> Weight in Motif </h3></th>
<th class="name" bgcolor="#999999"><h4> Segment & Stocks</h3></th>
<th class="price" bgcolor="#999999"><h4> Name of stock </h3></th>
</thead>
<% h.each do |stock| %>
<tr id="titles" value="Disable Sort">
<th bgcolor="#CCCCCC"> <h5> <%= stock["weight"] %> </th>
<th bgcolor="#CCCCCC"> <h5> <%= stock["folder"] %> </th>
<th bgcolor="#CCCCCC"> <h5> </th>
</tr>
<% stock["stocks"].each do |details| %>
<tr id="Stocks">
<th> <%= details["weight"] %> </th>
<th> <%= details["id"] %> </th>
<% a=details["name"] %>
<% a.gsub! /\s+/, '-' %>
<% str="www.dalal-street.in/" %>
<% str=str +a %>
<% str=str[0..-2] %>
<td id="<%= details["name"] %>">
<%= link_to h(details["name"]), str %>
</td>
</tr>
<% end %>
<% end %>
</table>
使用 jquery 我正在使用拖放更改股票位置。即是从文件夹 test 3 到 test 的 stock id 3。现在我需要将其更新为我的反手。有什么方法可以让我的 h 变量根据表格更新为新值。