Inheritance 继承和淘汰
如果我称之为:Inheritance 继承和淘汰,inheritance,knockout.js,coffeescript,Inheritance,Knockout.js,Coffeescript,如果我称之为: class ViewModel constructor: -> $.ajax({url: '#.json', type: 'GET', dataType: 'json'}) .done @buildModel buildModel: (data) => @model = ko.mapping.fromJS(data) @model.update = => delete @model.update
class ViewModel
constructor: ->
$.ajax({url: '#.json', type: 'GET', dataType: 'json'})
.done @buildModel
buildModel: (data) =>
@model = ko.mapping.fromJS(data)
@model.update = =>
delete @model.update
jsonForm = ko.mapping.toJSON(@model)
$.ajax({url: '#.json', data: jsonForm, type: 'PUT', contentType:"application/json; charset=utf-8", dataType: 'json'})
.done @buildModel
ko.applyBindings(@model)
###################################################################
class FormViewModel extends ViewModel
buildModel: =>
super()
一切都很好。如果我试图继承
$(document).bind 'pageinit', =>
@form = new ViewModel
获取错误:
$(document).bind 'pageinit', =>
@form = new FormViewModel
为什么ko.applyBindings对这种继承不满意?在
FormViewModel
的buildModel
函数中使用super
的意思是:调用同名的父方法,不带任何参数super()
的意思是:使用我收到的任何参数调用同名的父方法super
undefined
调用父buildModel
函数
还要注意,我认为您不需要在buildModel
函数中调用ko.applyBindings
。整个视图模型只需调用一次
Uncaught Error: Unable to parse bindings.
Message: ReferenceError: update is not defined;
Bindings value: click: update