我试图使用Quicksand插件来修饰Rails中AJAX调用的响应:
链接:
<% Project.services.each_with_index do |service, index| %>
<%= link_to_function(service, "regatherProjects('#{service}', #{index})", :id => "service_link_#{index}") %>
<%= " / " if !index.eql?(Project.services.length - 1) %>
<% end %>联署材料:
function regatherProjects(service_name, service_id) {
$.get("/index_project_update", { service: service_name }, function(data) {
$('#home_projects').quicksand($(data), {
adjustHeight: 'dynamic'
});
});
$('#home_services').find('a').removeClass("on");
$('#service_link_' + service_id).addClass("on");
};主计长:
def index_project_update
if params[:service] && !params[:service].blank?
@projects = Project.highlighted.where(:service => params[:service])
else
@projects = Project.highlighted
end
end查看:
$("#home_projects").replaceWith("<%= j(render('projects')) %>")项目:
<div id="home_projects">
<% if @projects.empty? %>
<p>No projects. <%= link_to_function("View All", "regatherProjects('')") %>.</p>
<% else %>
<ul class="all_projects">
<% @projects.each_with_index do |project, index| %>
<li data-id="<%= project.customer.name.underscore.downcase %>_<%= project.name.underscore.downcase %>">
<%= link_to(image_tag(project.project_images.first.image.home), project) %>
</li>
<% end %>
</ul>
<% end %>
</div>我认为的问题是,AJAX请求返回的数据(参见下面)并不是所期望的格式,但我不知道如何从响应中推断相关信息。来自AJAX请求的响应如下:
$("#home_projects").replaceWith("<some><html><that><i><need>")因此,问题在于,当它应该使用替换的HTML时,它使用上面的代码作为Quicksand的目标代码:
<some><html><that><i><need>AJAX请求运行得很好,但是我需要将Quicksand集成到这里。
我需要:
的目的地代码的方法。
如果我遗漏了你认为需要帮助的任何信息,请问。
这是我在堆栈溢出问题上提出的第一个问题,所以我有义务为任何误用行为道歉。
发布于 2012-04-19 08:23:41
如果有人遇到类似的问题,那么在Chrome、火狐、IE9、IE8和IE7中,以下内容对我都有帮助。
链接:
<% Project.services.each_with_index do |service, index| %>
<%= link_to_function(service, "regatherProjects('#{service}', #{index})", :id => "service_link_#{index}") %>
<%= " / " if !index.eql?(Project.services.length - 1) %>
<% end %>联署材料:
function regatherProjects(service_name, service_id) {
$.get("/index_project_update.html", { service: service_name }, function(data) {
$('.all_projects').quicksand($(data).find('li'), {
adjustHeight: 'dynamic'
});
});
$('#home_services').find('a').removeClass("on");
$('#service_link_' + service_id).addClass("on");
};路由:
match '/index_project_update' => 'application#index_project_update', :defaults => { :format => 'html' }主计长:
def index_project_update
if params[:service] && !params[:service].blank?
@projects = Project.highlighted.where(:service => params[:service])
else
@projects = Project.highlighted
end
render :layout => false
end查看:
<%= render('application/index/projects') %>项目:
<div id="home_projects">
<% if @projects.empty? %>
<ul class="all_projects">
<li data-id="project">No projects. <%= link_to_function("View All", "regatherProjects('')") %>.</li>
</ul>
<% else %>
<ul class="all_projects">
<% @projects.each_with_index do |project, index| %>
<li data-id="project_<%= project.id %>">
<%= link_to(image_tag(project.project_images.first.image.home, :alt => (project.customer.name + " - " + project.name), :title => (project.customer.name + " - " + project.name)), project) %>
</li>
<% end %>
</ul>
<% end %>
</div>https://stackoverflow.com/questions/10188545
复制相似问题