さまざまな優先度のランクを示すJSON文字列があります。jsonのキーはランク付けされた番号であり、そのキーの値は優先度テーブルにある優先度のIDです。例:{"1":2、 "2":3、 "3"、1}
このJSONをmysqlのPRIORITY_RANKS列にコーチ用に保存します。RailsアプリのCOACHES/EDITページで作業しています。優先度を、JSON文字列が示す順序でリストに並べ替えることができる必要があります。順序の代わりに、それらはmysqlにあります。
どういうわけか、JSON文字列を解析し、それに応じて優先度を並べ替える必要があります。ソート可能な機能のためにjqueryUIを使用しています。ここにリストのサンプルがあります。これ以上の情報が必要な場合はお知らせください。私はまだ初心者の笑のほんの少しの経験があります!
表示/編集`
<td style="padding:20px;">
<label class="pc3">Drag to Rank Priorities for Coach</label>
<p class="priochecker">Uncheck to disable Priorities</p>
<div id="rightlist">
<input type="hidden" name="currentranks" id="currentranks"></input>
<ul id="sortable" style="list-style:none;">
<% @priorities.each do |x, count| %>
<li class="digit"><input class="priobox" type="checkbox" id="<%= x.id %>" name="<%= x.name %>" value="<%= x.id %>" onclick="removeval(this,<%= x.id %>);" checked>
<strong>Rank <span class='prilistid'></span> <%= x.name %></strong></li>
<% end %>
</ul>
</div>
</td>
</tr>
</table>
</div>
<input type="hidden" name="coach[priority_ranks]" id="hash" value="{'1':1,'2':2,'3':3}"></input>
COACHES_CONTROLLER
def edit
#@coach = @current_coach
@locations = Location.find(:all, :order => "name")
@levels = Level.find(:all, :order => "value")
@coach = Coach.find(params[:id])
@ranks = Array.new
@current_site = @coach.sites
@priority_ranks = @coach.priority_ranks
@priorities = Priority.find(:all, :conditions => { :deleted => false })
siteObj = Site.all
@sites = {}
@sites['All Sites'] = -1
siteObj.each do |t|
@sites[t.name] = t.id
end
end