基本上,我想显示3种不同的视图,具体取决于" wheel"我们正在关注。所以我创建了3个不同的JST模板。显示的初始默认视图是Cars / first_wheel模板。当我点击ID为#next-step的按钮时,当我看到警报(滚轮)消息框时,会触发渲染功能。但呼吁" $(@ EL)的.html(...)"不会改变所显示内容......为什么会这样?
Backbone.View.prototype.eventAggregator = _.extend({}, Backbone.Events);
class Wheel.Views.CarsFirstwheel extends Backbone.View
initialize: ->
_.bindAll(this, 'render','nextwheel', 'prevwheel');
@collection = new Wheel.Collections.Cars
Car_state = new Wheel.Models.Car(
current_wheel: 0
next_wheel: 1
prev_wheel: 2
current_view: ""
)
@collection.add(Car_state)
@eventAggregator.bind("call_render", @render);
wheel1_template: JST['Cars/first_wheel'],
wheel2_template: JST['Cars/second_wheel']
wheel3_template: JST['Cars/third_wheel']
render: ->
wheel = @collection.at(0).get 'current_wheel'
switch 0
when 0
$(@el).html(@wheel1_template())
alert(wheel)
when 1
$(@el).html(@wheel2_template())
alert(wheel)
when 2
$(@el).html(@wheel3_template())
alert(wheel)
this
nextwheel: ->
Car_state = @collection.at(0)
count = ((Car_state.get 'current_wheel')+1)%3
Car_state.set
current_wheel: count
Car_state.save
@collection.fetch
@eventAggregator.trigger("call_render")
prevwheel: ->
Car_state = @collection.at(0)
count = (Car_state.get 'current_wheel'-1)%3
Car_state.set
current_wheel: count
Car_state.save
@collection.fetch
events: ->
'click #next-wheel': 'nextwheel'
答案 0 :(得分:0)
没关系 - 我忘了改变0"切换0"回到车轮。当我这样做时,一切正常。