在我的backbonejsexample.com/?stat=#users
应用程序中,当我导航到时,应用程序会自动重新加载页面router.navigate('users')
?
当我点击后退按钮时,它会加载 url example.com/#users
,因此它可以正确访问所需的页面,然后加载example.com/?stat=#users
。
我遇到了什么问题,我尝试更改trigger
选项但无法修复?而且我无法找到更多关于它是什么的信息?state=#...
(我可以做出假设,但简明的文档会非常有帮助)?
一个精简的路线文件:
class window.AppRouter extends Backbone.Router
routes:
"": "list"
"users": "list"
"user/:id": "userDetails"
list: ->
@before()
before: (callback) ->
if @users?
callback() if callback?
else
@users = new Users
@users.fetch(
success: ->
$('#sidebar').html(new UsersView({model: app.users}).render().el)
callback() if callback)
userDetails: (id) ->
@before ->
user = app.users.get( id)
if user?
console.log('inside if')
app.showView( '#content', new UserView( {model: user}))
showView: (selector, view) ->
@currentView.close() if @currentView?
$(selector).html(view.render().el)
@currentView = view
return view
我的精简视图文件:
class window.UsersView extends Backbone.View
tagName:'ul'
className: 'nav nav-pills nav-stacked'
initialize: ->
@userViews = new Array
@model.bind("reset", @render, this)
@model.bind("add", (user) =>
@$el.append( new UserInListView({model: user}).render().el))
render: (event) ->
_.each(
@model.models
(user) =>
userView = new UserInListView( {model: user})
@userViews.push( userView)
@$el.append( userView.render().el)
this)
return this
class window.UserInListView extends Backbone.View
tagName:"li"
initialize: ->
@template = _.template(tpl.get('user_in_list'))
@model.bind("change", @render, this)
@model.bind("destroy", @close, this)
render: (event) ->
@$el.html( @template( @model.toJSON()))
return this
events:
"click a": "select"
select: ->
$("#sidebar>ul>li.active").removeClass("active")
@$el.addClass( 'active')
app.navigate("user/#{@model.id}", true)
class window.UserView extends Backbone.View
initialize: ->
templateName = 'user_edit'
@template = _.template(tpl.get(templateName))
@model.bind("change", @render, this)
events:
"click .cancel": "cancel"
cancel: ->
@remove()
app.navigate('users', false)
我只是不确定是什么原因造成的,是绑定吗?它是推特引导程序吗?这是我设置路由器的方式吗?为什么当我直接访问 url 时我没有遇到问题,但是当我的路由器将我导航到那里时我会遇到问题?