我开发了第一个主干RESTfull应用程序。我有以下观点:
var app = app || {};
app.AssessorsCollectionView = Backbone.View.extend({
el: '#assessors',
tagName: 'table',
events:{
"submit form": "searchAssessors"
},
initialize: function() {
this.collection = new app.AssessorsCollection();
this.collection.fetch({reset: true, data: $.param({ online: false}) });
this.render();
this.listenTo( this.collection, 'reset', this.render );
},
render: function() { /// },
renderRegion: function( item ) { /// },
searchAssessors: function( e ) {
e.preventDefault();
this.collection.remove();
console.log("EVENT");
}
});
这是我的HTML表单:
<form id="form-search-assessors" class="form-horizontal" role="form">
.........
<input id="search-assessors-button" class="btn btn-lg btn-success btn-block" type="submit" value="Search" />
<!--<button id="search-assessors-button" class="btn btn-lg btn-success btn-block" type="submit">Search</button>-->
</form>
我在searchAssessors上设置了断点,但是它不起作用。另外,我在控制台中看不到任何消息。
我的问题的解决方案:
$( "form#form-search-assessors" ).submit($.proxy(function(e) {
e.preventDefault();
console.log(this);
this.collection.fetch({reset: true, data: $.param({ online: true}) });
this.render();
}, this));
消息来源是:https ://stackoverflow.com/a/9813760/1756750
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句