我已经使用打字稿将我的视图模型分离到类中。
现在在我的引导程序中,我正在像这样导入它们:
import dl = module("DataLayer");
import vm1 = module("AppBarViewModel");
import vm2 = module("Nav2ViewModelCommander");
import vm3 = module("IdentityViewModel");
有没有办法将它们收集到一个命名空间?我正在使用 requirejs,当编译为 js 时,我的视图模型看起来像这样。
define(["require", "exports"], function(require, exports) {
var AppBarViewModel = (function () {
function AppBarViewModel() {
this.visible = ko.observable(true);
this.buttons = ko.observableArray([]);
this.enableContext = ko.observable(true);
this.canClose = ko.computed(function () {
var k = ko.utils.arrayFirst(this.buttons(), function (b) {
return b.blockHide && b.blockHide == true;
});
return k == null;
});
}
AppBarViewModel.prototype.addButton = function (data) {
this.buttons.push(data);
this.visible(data.blockHide && data.blockHide == true);
};
AppBarViewModel.prototype.removeButton = function (data) {
this.buttons.remove(data);
this.visible(!this.canClose());
};
return AppBarViewModel;
})();
exports.AppBarViewModel = AppBarViewModel;
})
从
///<reference path="../knockout.d.ts" />
///<reference path="../require.d.ts" />
declare var ko: any;
export class AppBarViewModel {
visible = ko.observable(true);
buttons = ko.observableArray([]);
enableContext = ko.observable(true);
addButton(data) {
this.buttons.push(data);
this.visible(data.blockHide && data.blockHide == true);
}
removeButton(data) {
this.buttons.remove(data);
this.visible(!this.canClose());
}
canClose = ko.computed(function () {
//var buttons = self.buttons();
//ko.utils.arrayForEach(self.buttons(), function () { return });
var k = ko.utils.arrayFirst(this.buttons(), function (b) { return b.blockHide && b.blockHide == true });
return k == null;
});
constructor() {
}
}