我试图让状态进入我的脊椎应用程序。单击时,会将一个项目添加到列表中。然后创建一个 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()