在我的流星旅程的下一個階段(閱讀:學習繩索!),我想實現一個基於用戶輸入值的簡單搜索,然後重定向到一個特定的路由到從服務器返回的記錄。使用流星和鐵路路由器實現一個簡單的搜索
目前,我通過這個代碼拿起在輸入的值:
Template.home.events 'submit form': (event, template) ->
event.preventDefault()
console.log 'form submitted!'
countryFirst = event.target.firstCountrySearch.value
countrySecond = event.target.secondCountrySearch.value
Session.set 'countryPairSearchInputs', [countryFirst, countrySecond]
countryPairSearchInputs = Session.get 'countryPairSearchInputs'
console.log(countryPairSearchInputs)
return Router.go('explore')
令人高興的是,控制檯日誌返回所需countryPairSearchInputs
變量 - 兩個ID的數組。在我routes.coffee文件然後我有以下幾點:
@route "explore",
path: "/explore/:_id"
waitOn: ->
Meteor.subscribe 'countryPairsSearch'
在服務器端,我有:
Meteor.publish 'countryPairsSearch', getCountryPairsSearch
最後,我有一個search.coffee文件在我/ lib目錄下定義getCountryPairsSearch
函數:
@getCountryPairsSearch = ->
CountryPairs.findOne $and: [
{ country_a_id: $in: Session.get('countryPairSearchInputs') }
{ country_b_id: $in: Session.get('countryPairSearchInputs') }
]
關於搜索函數本身,有一個CountryPairs
集合,其中每個記錄有兩個ID(country_a_id
和country_b_id
) - 這裏的目的是讓用戶輸入兩個國家,然後返回相應的CountryPair
。
我目前正在努力所有的作品聯繫在一起 - 在搜索控制檯輸出是目前:
Uncaught Error: Missing required parameters on path "/explore/:_id". The missing params are: ["_id"]. The params object passed in was: undefined.
任何幫助將不勝感激 - 因爲你可能會說我是新來的流星我仍然習慣於發佈/訂閱方法!
編輯:混淆客戶端/服務器的發佈方法,當我第一次發佈 - 深夜發佈的危險!
謝謝 - 我居然做了一個錯字RE:在服務器/客戶端我原來的問題,但在會議上的頭。得不到服務器端的幫助! – Budgie 2015-04-01 07:57:27