这是现在工作。以下是此代码的修改版本。var data = $.getJSON("URL", null, function (result) {
var notes = function () {
self = this;
self.notes = ko.observableArray(result);
self.deleteNote = function (note) {
$.ajax({
url: "URL" + this.ID,
dataType: "json",
type: "GET",
success: function (d) {
self.notes.remove(note);
}
});
};
self.addNote = function () {
var note = $("#txtNote").val();
$.ajax({
url: "URL",
type: "POST",
data: { 'note': note },
datatype: "json",
success: function (data) {
self.notes.push({ Description: note, ID: data.ResponseData.id, CreateDate: data.ResponseData.createDate });
}
});
}
}
ko.applyBindings(new notes());
});
谢谢, JSHunjan