我正在尝试使用 jquery selectable 来替换我丑陋的复选框。我将此代码添加到我的 form_for 中,但我不知道如何将 tag_list 数组传递回我的控制器。
<meta charset="utf-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<style>
#feedback { font-size: 1.4em; }
#selectable .ui-selecting { background: #FECA40; }
#selectable .ui-selected { background: #F39814; color: white; }
#selectable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
#selectable li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
</style>
<script>
$(function() {
$( "#selectable" ).selectable({
stop: function() {
var result = $( "#select-result" ).empty();
var tag_names = []
$( ".ui-selected", this ).each(function() {
var item = this.innerHTML;
result.append( ( item ) );
tag_names.push( item )
});
}
});
});
</script>
</head>
<body>
<p id="feedback">
<span>Tags:</span> <span id="select-result">none</span>.
</p>
<ol id="selectable">
<%@tags.each_key do |tag| %>
<li class="ui-widget-content"> #<%=tag%> </li>
<%end%>
</ol>