我需要使用BackboneJS (使用CoffeeScript)设置一个简单的CRUD应用程序
在我的视图中似乎不能处理一个简单的表单。
<form role="form">
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title">
</div>
<div class="form-group">
<label for="code">Code</label>
<input type="text" class="form-control" name="code">
</div>
<button type="submit" class="submit">Submit</button>
</form>在我看来,我有:
define [
'jquery'
'underscore'
'backbone'
'templates'
], ($, _, Backbone, JST) ->
class SimpleView extends Backbone.View
template: JST['app/scripts/templates/simple.hbs']
events:
'submit': 'submit'
render: ->
$('.content').html(@template())
submit: (event) ->
console.log 'submit', event
@$('input[name=title]').val()
view = new SimpleView()尽管如此,当我提交表单时,什么也没有发生。
我做错了什么?
============SOLVED=============呈现函数未将模板添加到视图的el
发布于 2014-03-10 04:51:03
您可能没有正确侦听事件(即不确定submit事件是否会传播到您正在侦听的视图级别)。尝试收听表单submit:
events:
'submit form': 'submit'https://stackoverflow.com/questions/22286445
复制相似问题