0

私の backbone.js ビューの 1 つに、次のコードがあります。

  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.ajaxsaveを使用するため、fetchやなどのメソッド内で jQuery.ajax オプションを渡すだけで済みますdestroy

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