0

在我看来,我有一些 UJS 旨在替换部分内容。.js 文件如下所示:

transition("#content_container", "<%= escape_javascript(render 'users/show') %>");
librarySorter("User", "<%= @user.username %>");

转换函数按预期执行,但 librarySorter 未执行。我检查了萤火虫,它确实出现在我的回复中,如下所示:

librarySorter("User", "tbaron");

更奇怪的是,如果我将该行复制并粘贴到我的 firebug 控制台中,它会正常运行并执行。我已经修改了几个小时,但我仍然不知道为什么它不起作用。有任何想法吗?

作为参考,下面是 librarySorter 的样子(在 application.js 中):

function librarySorter(library_type, id){
  function publication_sort_binder(type, order, name){
    $("#overview_table").animate({opacity: 0}, 400);
    $("#sort_method").html(type+' '+order);
    var url = library_type == "User" ? '/users/'+id+'/owned_publications' : '/groups/'+id+'/overview_sort'
    $.ajax({
      type: 'GET',
      data: {'function':type+' '+order},
      url: url,
      success: function() {
        $("#publication_sort_arrow").remove();
        var arrow = (order == 'ASC') ? '&darr;' : '&uarr;';
        $('#sort_'+name).unbind("click").click(function() {
          publication_sort_binder(type, (order == 'ASC') ? 'DESC' : 'ASC', name);
      }).append("<span id='publication_sort_arrow'> "+arrow+"</span>");
      }
    });
  }
  $('#sort_title').click(function() {
    publication_sort_binder("publications.title", "DESC", "title");
  })
  $('#sort_author').click(function() {
    publication_sort_binder("contributors.name", "DESC", "author");
  })
  $('#sort_review_date').click(function() {
    publication_sort_binder("reviews.created_at", "DESC", "review_date");
  })
  $('#sort_review_vote').click(function() {
    publication_sort_binder("reviews.votes_sum", "DESC", "review_vote");
  })
  $('#sort_children_total').click(function() {
    publication_sort_binder("updates.replies_count", "DESC", "children_total");
  })
}
4

0 回答 0