开发者

two sortable lists need to get serialize parameters using jquery-ui

开发者 https://www.devze.com 2022-12-26 05:30 出处:网络
Can you help me with these codes: app/views/admin/articles/position.html.haml - form_tag update_position_admin_articles_path do

Can you help me with these codes:

app/views/admin/articles/position.html.haml

- form_tag update_position_admin_articles_path do
  .grid_5.alpha{:id => 'article-container'}
    %h3 Articles
    %ul#articles.connectedSortab开发者_如何转开发le
      - for article in @articles
        = content_tag(:li, article[0], :id => article[1], :class => 'ui-state-default')
  .grid_5.omega{:id => 'feature-container'}
    %h3 Featured Articles
    %ul#features.connectedSortable
      - for feature in @features
        = content_tag(:li, feature[0], :id => feature[1], :class => 'ui-state-highlight')
  %br.clear
  = submit_tag "Update Position"

public/application.js

$(function() { 
    $("#articles, #features").sortable({ 
        connectWith: '.connectedSortable',
        update: function(event, ui) { 
                console.log($(this).sortable("serialize"));
            }
        }) 
    });

It's two sortable lists and I need to get the serialize parameter of those lists to be passed when I click the submit button but I always get "(an empty string)" on console.log(). I'm using jQuery-ui for this functionality.


Just in case anyone bumped into this same problem. Solved this problem with this code:

app/views/admin/articles/position.html.haml

- form_tag update_position_admin_articles_path do
  .grid_5.alpha{:id => 'article-container'}
    %h3 Articles
    %ul#articles.connectedSortable
      - for article in @articles
        = content_tag(:li, article[0], :id => article[1], :class => 'ui-state-default')
  .grid_5.omega{:id => 'feature-container'}
    %h3 Featured Articles
    %ul#features.connectedSortable
      - for feature in @features
        = content_tag(:li, feature[0], :id => feature[1], :class => 'ui-state-highlight')
  = hidden_field_tag 'sort[articles]', ''
  = hidden_field_tag 'sort[features]', ''
  %br.clear
  = submit_tag "Update Position"

public/application.js

$(function() { 
    $("#articles, #features").sortable({ 
        connectWith: '.connectedSortable',
        update: function(element, ui) { 
                var result = $(this).sortable('toArray');
                var data = {};
                data[this.id] = result;
                document.getElementById('sort_' + this.id).value = result;
            }
        }) 
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号