我正在尝试通过 AJAX 提交提取数据并将其呈现到#search_results
主干中的 div 中。我该怎么做呢?我对骨干完全陌生,仍在学习。
谢谢!
RoR 控制器:
class ClassroomsController < PublicController
def search
@search_result = Classroom.first
respond_with @search_result
end
end
RoR 视图:
= form_tag search_path, :method => :get, :id => "search_form", do
= text_field_tag :search_textbox
= submit_tag "Search", :id => "search_button"
#search_results
教室/search.js.erb:
$("#search_results").html("<%=escape_javascript(render 'search')%>");
教室/search.html.haml:
= @search_result.classroom.title
主干.js 视图:
class Classrooms.Views.Classroom extends Backbone.View
events:
"submit #search_button": "getResults"
render: ->
$(@el).html($("#classroom_main").html())
@setActiveNavItem("main")
this
getResults: (event) ->
event.stopPropagation()
event.preventDefault()
$.get $(this).attr("action"), $(this).serialize(), null, "script"
return false