编辑:原来我的问题是 ID10T 错误。我复制了一个具体的类定义,但忘记更改名称。JavaScript 很高兴地让我重新定义实体,而无需任何与 Knockout 相关的方法。哦!
这个问题建立在对另一个Knockout/inheritance question的回答之上。使用该问题的答案,我能够建立一个基本的层次结构。但是,我想像通常使用对象数据一样使用映射插件。但是,当我尝试使用映射时,我的淘汰子类的行为并不像它应该的那样。
这是代码的一部分:
tubs.Gen2Event = function (data) {
var self = this;
//...Set a bunch of props...
return self;
}
tubs.Gen2LandedEvent = function (data) {
var self = this;
ko.utils.extend(self, new tubs.Gen2Event(data));
// If I exclude the following mapping call, the object is fine
ko.mapping.fromJS(data, {}, self);
//...Other methods that worked fine before mapping...
}
我熟悉自定义映射,但据我所知,它似乎是为了微调子属性,而不是修改整个对象。