0

在我的一个backbone.js 视图中,我有以下代码:

  events:
    'click .filter_classroom_size': 'filterClassroom'

  filterClassroom: (event)->
    event.stopPropagation()
    event.preventDefault()
    Backbone.history.navigate("classrooms?nationality", true)

我的路由器有以下代码:

  routes:
    'classrooms?:filter': 'classrooms'

  initialize: ->
    @collection = new Classrooms.Collections.Entries()
    @collection.fetch()

  classrooms: (filter) ->
    classroomView = new Seats.Views.ClassroomIndex(collection: @collection)
    $('#output_container').html(classroomView.render().el)
    alert("#{filter}") # this prints out the filter parameter

教室控制器.rb:

class ClassroomsController < ApiController
  def show
    # How do I send a parameter here so I can filter on it?
    respond_with Classroom.all
  end
end

我希望能够将参数传递给控制器​​,以便过滤数据库结果。

谢谢!

4

1 回答 1

0

Backbone 在后台使用jQuery.ajax,因此您可以简单地在方法中传递 jQuery.ajax 选项,例如save,fetchdestroy.

initialize: ->
  @collection = new Classrooms.Collections.Entries()
  @collection.fetch
    data:
      your_key: your_value
于 2012-07-06T06:00:12.630 回答