问题在于第二个show view
之后。 this.ui.uielemnet
不是返回一个元素,而只是一个字符串选择器。事件和其他逻辑运作良好,但我可以t get element after second
show vie . In the first
显示视图“一切工作如刨。Marionette JS 3:ui在第二个显示视图后有字符串选择器
代码如下。我添加控制台日志进行解释。 CoffeeScript的)
路由器:
class App.Routers.PanelRouter extends Marionette.AppRouter
initialize: (options = {}) ->
@mainView = options.cpView
routes:
'sbis-docs(/)': 'sbisDocShow'
'sbis-send(/)': 'sbisSendShow'
sbisDocShow: ->
view = new App.Views.SbisDoc
@mainView.getRegion('childRegion').show view
view.showTable()
sbisSendShow: ->
view = new App.Views.SendSbis
@mainView.getRegion('childRegion').show view
part of view
class App.Views.SendSbis extends Marionette.View
template: _.template(App.Templates.SbisSend);
initialize:() ->
vent.on('event:change-search-method', @changeSearchMethod)
vent.on('event:change-send-method', @changeSendMethod)
changeSearchMethod: (data) =>
if data.checked
@ui.cust.attr('placeholder', 'Customer ID')
@ui.labelCust.text('Номер договора')
else
@ui.cust.attr('placeholder', 'Логин')
@ui.labelCust.text('Логин пользователя')
changeSendMethod: (data) =>
console.log @ui.month
if data.checked
@ui.month.prop('disabled', false)
else
@ui.month.prop('disabled', true)
ui:
sendDocs: '#send-docs'
form: '#form-docs'
cust: '#cust'
year: '#year'
month: '#month'
labelCust:'#label-cust'
另一种观点:
class App.Views.SetupSend extends Marionette.View
template: _.template(App.Templates.SetupSend)
onAttach: ->
@ui.checkboxes.bootstrapToggle()
ui:
search: '#search-method'
send: '#send-method'
checkboxes: 'input[type=checkbox][data-toggle^=toggle]'
events:
'change @ui.search': 'changeSearchMethod'
'change @ui.send': 'changeSendMethod'
changeSearchMethod: (e) ->
vent.trigger('event:change-search-method', e.target)
changeSendMethod: (e) ->
vent.trigger('event:change-send-method', e.target)
在changeSendMethod: (data)
控制台日志第一次是 [input#month.form-control, prevObject: r.fn.init[1]]
但是当我改变路线并再次复出是CONSOLE.LOG #month
如果我将更改为@ui.month.prop('disabled', false)
$(@ui.month).prop('disabled', false)
这将是工作。但我不明白为什么会发生,我怎么能解决它。