requirejs - knockout.mapping & Require.js Bug

  显示原文与译文双语对照的内容
0 0

所以我尝试将 knockout.mapping.js 与 require.js. 集成在一起:我已经尝试了这个例子。

不幸的是,我一直在遇到这个错误:

获取 http://[url]/Scripts/app/contractor/ko.js 404 ( 未找到)
未捕获的错误:脚本错误: KO

我已经设置了以下文件:

app.index.js


requirejs.config({
"baseUrl":"../Scripts/app/contractor",
"paths": {
"app.index":"app.index",
"knockout":"//cdnjs.cloudflare.com/ajax/libs/knockout/2.2.1/knockout-min",
"mapping":"//cdnjs.cloudflare.com/ajax/libs/knockout.mapping/2.3.5/knockout.mapping",
"knockout.bindings":"../../lib/knockout.bindings",
"fu":"../../lib/jquery.fineuploader-3.8.0",
"s2":"../../lib/select2",
"jquery":"//code.jquery.com/jquery-latest.min",
"jqueryui":"//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min",
"moment":"../../lib/moment.min",
"toastr":"../../lib/toastr"
 },
"shim": {
 'mapping': {
 deps: ['knockout'],
 exports: 'mapping'
 }
 }
});

//Load the main app module to start the app
require(['knockout', 'mapping',"main.index"], function (ko, mapping, bs) {
 ko.mapping = mapping;
 alert('ko: ' + ko + ', mapping: ' + ko.mapping);
 bs.run();
});

main.index.js


 define(['knockout',
 'mapping',
 'indexViewModel'],
 function (ko, mapping, indexViewModel) {
 var
 run = function () {

 var vm = new indexViewModel();


 ko.applyBindings(vm, document.getElementById('#contractor-home-view'));
 };
 return {
 run: run
 };
 });

因为映射没有正确加载,所以 main.index.js 在这一点上是不相关的。 我 在 这儿 写错 了 吗?

时间: 原作者:

0 0

尝试在你的.config 中做这个


"shim": {
 'knockout': {
 exports: 'ko'
 },
 'mapping': {
 deps: ['knockout'],
 exports: 'mapping'
 }
 }

原作者:
...