我正试图让状态进入我的脊椎应用程序。单击时,项目将添加到列表中。然后创建一个url并导航到,然后呈现列表。但是,当我使用浏览器“后退”功能时,列表不会更改回以前的状态。如何让这个工作?
这是相关的代码,我遗漏了看似无关紧要的内容,但如果需要更多,我会提供它。
class App extends Spine.Controller
constructor: ->
super
@products = new Products
@filters = new Filters
Filter.bind 'filterAdded', => @navigateAfterFilterChange()
Filter.bind 'filterRemoved', => @navigateAfterFilterChange()
Spine.Route.setup( history: false )
renderAll: ->
@products.render()
@filters.render()
navigateAfterFilterChange: ->
Spine.Route.navigate( encodeURIComponent( JSON.stringify( _.map( Filter.active_filters, ( filter ) -> { t: filters.type, v: filters.value } ) ) ) )
class Filter extends Spine.Model
listen: => #This is used to make the right list item listen to a click event
$("'a[data-cid=\"#{ @id }\"]'").one 'click', @triggerFilter
triggerFilter: (e) =>
e.preventDefault()
filter = Filter.find( $( e.currentTarget ).attr( 'data-cid' ) )
if @active
@active = false
Filter.active_filters = _.reject Filter.active_filters, (x) -> ( x.type is filter.type and x.value is filter.value )
@save()
Filter.trigger 'filterRemoved', @
else
@active = true
Filter.active_filters.push filter
@save()
Filter.trigger 'filterAdded', @
class Filters extends Spine.Controller
constructor: ->
super
@utils = new GeneralScripts
@createFilters()
@listenForTypeActivation()
@routes
"": ( params ) ->
@render()
"*glob": ( params ) ->
@render()
答案 0 :(得分:0)
不确定,但看起来您可能需要使用render()
发送paramsclass Filters extends Spine.Controller
constructor: ->
super
@utils = new GeneralScripts
@createFilters()
@listenForTypeActivation()
@routes
"": ( params ) ->
@render(params)
"*glob": ( params ) ->
@render(params)
你还需要在渲染方法中处理params