我有观点:
class FoursquareSearch.Views.SearchNew extends Backbone.View
tagName: 'sidebar'
template: JST["templates/search/new_search"]
#events:
# 'submit': 'create'
initialize: ->
@render
render: ->
console.log('hello')
$this = $('#sidebar')
$this.html('<p>All new content. <em>You bet!</em></p>')
$this
使用此路由器
class FoursquareSearch.Routers.Maps extends Backbone.Router
routes:
'': 'index'
index: ->
FoursquareSearch.Views.maps = new FoursquareSearch.Views.Maps()
@model = new FoursquareSearch.Models.Map()
#originForm = new Traveltime.Views.ShapesOriginForm(model: model, map: Traveltime.Views.map)
newSearch = new FoursquareSearch.Views.SearchNew(model: model, map: FoursquareSearch.Views.maps)
这个HTML
<div id="top"></div>
<div id="sidebar">
</div>
初始化代码:
window.FoursquareSearch =
Models: {}
Collections: {}
Views: {}
Routers: {}
init: ->
new FoursquareSearch.Routers.Maps()
Backbone.history.start()
$(document).ready ->
FoursquareSearch.init()
我可以看到console.log
消息,但HTML类/ ID没有更新!
如果我跑:
$this = $('#sidebar')
$this.html('<p>All new content. <em>You bet!</em></p>')
在控制台中我可以看到页面上的HTML更改,看来Backbone.js似乎不想为我更新视图?
答案 0 :(得分:1)
在初始化方法中将@render更新为@render()。您只是返回方法,但从不调用它。