我的打字稿文件生成以下输出,但我得到一个 ko 在我的 AppViewModel 中未定义。欢迎任何关于我如何解决这个问题的指示。带有打字稿的视觉工作室解决方案在这里:https ://github.com/s093294/typescript-knockout
/Scripts/App/config.js
require.config({
baseUrl: '/Scripts/App/',
paths: {
'jQuery': '/scripts/jquery-1.9.1',
'knockout': '/scripts/knockout-2.2.1.debug',
'AppViewModel': '/Scripts/ViewModels/AppViewModel'
},
urlArgs: "bust=" + (new Date()).getTime(),
shim: {
jQuery: {
exports: '$'
},
'knockout': {
deps: [
"jQuery"
],
exports: 'ko'
},
'AppViewModel': {
deps: [
'knockout'
]
}
}
});
require([
'AppViewModel'
], function (avm) {
var viewmodel = new avm.AppViewModel();
ko.applyBindings(viewmodel);
alert('hello world - SUCCESS');
});
/脚本/视图模型
define(["require", "exports", "knockout"], function(require, exports) { // I would like ko to be in the function handle, but typescript cant do this. But it should be in the global scope also right?
var AppViewModel = (function () {
function AppViewModel() {
this.title = ko.observable();
this.title('My Sample');
}
AppViewModel.prototype.setTitle = function (title) {
this.title(title);
};
return AppViewModel;
})();
exports.AppViewModel = AppViewModel;
})
索引.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Home</title>
</head>
<body>
Did you get a hello world?
<div data-bind="text: title"></div>
<script data-main="/Scripts/App/config" type="text/javascript" src="~/scripts/require.js"></script>
</body>
</html>