问题描述
这是来自tickout.dirtyFlag.js
This is from knockout.dirtyFlag.js
;(function (ko) {
ko.DirtyFlag = function (objectToTrack, isInitiallyDirty, hashFunction) {
hashFunction = hashFunction || ko.toJSON;
var
_objectToTrack = objectToTrack,
_lastCleanState = ko.observable(hashFunction(_objectToTrack)),
_isInitiallyDirty = ko.observable(isInitiallyDirty),
result = function () {
var self = this;
self.isDirty = ko.computed(function () {
return _isInitiallyDirty() || hashFunction(_objectToTrack) !== _lastCleanState();
});
self.reset = function () {
_lastCleanState(hashFunction(_objectToTrack));
_isInitiallyDirty(false);
};
return self;
};
return result;
};
})(ko);
在我的模型中,我有一个这样的定义设置:
In my model I have a define setup like this:
define([
"lib/knockout",
"lib/knockout.dirtyFlag"
],
function(ko) {
...
self.dirtyFlag = new ko.DirtyFlag([
}
基本上,我得到一个错误,指出DirtyFlag是未定义的.
basically I get an error saying that DirtyFlag is undefined.
我该怎么办?
推荐答案
好吧,看来我已经开始工作了,所以我将发布我的发现:
Well, looks like I got it working, so I'll post my findings:
在我的requirejs配置中,我添加了以下内容:
In my requirejs config I added this:
shim: {
"lib/knockout/knockout.dirtyFlag": {
deps: [
"lib/knockout/knockout"
],
init: function (ko) {
var self = this;
ko.DirtyFlag = self.ko.DirtyFlag;
return ko;
}
}
我对javascript或requirejs不太熟悉,但是init似乎将dep放在"ko"中,然后就可以在ko上创建一个DirtyFlag. self.ko.DirtyFlag是实际的kickout.dirtyFlag javascript.
I'm not very familiar with javascript or requirejs, but init seems to put the dep in "ko" and then I am able to create a DirtyFlag on ko. self.ko.DirtyFlag is the actual knockout.dirtyFlag javascript.
这篇关于如何使用requirejs加载koLite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!