3
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()
如果我把這叫做:繼承和knockoutjs
$(document).bind 'pageinit', =>
@form = new ViewModel
一切都很好。如果我嘗試繼承
$(document).bind 'pageinit', =>
@form = new FormViewModel
得到一個錯誤:
Uncaught Error: Unable to parse bindings.
Message: ReferenceError: update is not defined;
Bindings value: click: update
爲什麼ko.applyBindings是不滿意這點繼承?
非常感謝! – Jonas 2012-08-09 13:06:31