我有一个像这样的Marionette ItemView:
List.Chart = Backbone.Marionette.ItemView.extend({
template: "#chart-template",
className: "block container-fluid first",
onRender: function () {
// Do a few things
},
});
该模板有一个<select id="filter">
标签,里面有几个选项。我想在用户点击它并且发生了变化时访问<select>
标记的值。我是Marionette的新手。我尝试了几种方法,但没有人得到我的价值。谢谢。
您不希望在木偶视图中覆盖渲染,而应该利用onRender
http://marionettejs.com/docs/marionette.itemview.html#render--onrender-event
至于知道用户何时点击或更改了输入,您将希望利用事件哈希。 http://marionettejs.com/docs/marionette.view.html#viewevents
这实际上来自骨干。
所以它看起来像这样:
List.Chart = Backbone.Marionette.ItemView.extend({
template: "#chart-template",
className: "block container-fluid first",
events: {
"click #filter": "doSomething",
"change #filter": "doSomething"
},
doSomething: function() {}
});
对于额外的点,你应该干掉事件绑定并利用backbone.marionette免费提供的@ui插值。
List.Chart = Backbone.Marionette.ItemView.extend({
template: "#chart-template",
className: "block container-fluid first",
ui: {
"filter": "#filter"
},
events: {
"click @ui.filter": "doSomething",
"change @ui.filter": "doSomething"
}
});