ModelBinder 似乎不能与嵌套模型(骨干嵌套项目)一起使用。模型的更改不会传播到嵌套元素。更改输入值时,跨度值不会改变...如果 NestedModel用它工作的 DeepModel 替换。同样,如果 person.name 被删除并且 Model 只有一个级别(lastName 和 firstName),则 NestedModel 也可以工作。
<script type='text/coffeescript'>
$ ->
class MyModel extends Backbone.NestedModel
defaults:
person:
name :
firstName: 'Bob'
lastName: 'Sass'
window.model = new MyModel
FormView = Backbone.View.extend
initialize: ->
@modelBinder = new Backbone.ModelBinder();
@modelBinder.bind(@model,@el)
el: '#frm'
view = new FormView model: model
</script>
<body>
<form method="post" action="/test" id='frm'>
<div id="welcome"> Welcome, <span id='person.name.firstName'></span> <span id='person.name.lastName'></span>
<br><br>
Edit your information:
<input type="text" name="person.name.firstName" value="zz"/>
<input type="text" name="person.name.lastName" value="nn"/></div>
</form>