Knockout.js 杜兰达尔给了“一个机会”;无法读取属性';节点类型';“无效”的定义;错误
一直在玩Durandal 2.1.0,但似乎无法运行一个示例。当我在Chrome中运行它时,我得到一个错误“无法读取null的属性'nodeType' 文件夹结构为: -视图模型 |-vm1.js -剧本 |-杜兰达尔 -观点 |-vm1.html -Index.html index.htmlKnockout.js 杜兰达尔给了“一个机会”;无法读取属性';节点类型';“无效”的定义;错误,knockout.js,durandal,Knockout.js,Durandal,一直在玩Durandal 2.1.0,但似乎无法运行一个示例。当我在Chrome中运行它时,我得到一个错误“无法读取null的属性'nodeType' 文件夹结构为: -视图模型 |-vm1.js -剧本 |-杜兰达尔 -观点 |-vm1.html -Index.html index.html <html> <head> <title></title> <script src="Scripts/knockout-3.1.0.j
<html>
<head>
<title></title>
<script src="Scripts/knockout-3.1.0.js"></script>
<script src="Scripts/jquery-1.9.1.js"></script>
</head>
<body>
<script src="Scripts/require.js" data-main="Scripts\main"></script>
</body>
</html>
vm1.js:
define(['plugins/router'], function (router) {
return {
router: router,
activate: function () {
//This line never fires
alert();
}
}
});
PS:与nuget一起安装。假设任何JS错误都是打字错误,那么脚本本身就可以了。我尝试了各种方法来移动脚本加载顺序,使用viewLocator手动定义路径。似乎完全符合我在Durandal网站上看到的例子
非常感谢您的帮助。除非您直接指定路径或使用自定义viewLocator,否则您需要将视图目录和viewmodels目录放在同一级别上。换句话说,他们必须是树上的兄弟姐妹 在main.js中查看我们的主要入口点。我已经删除了不相关的部分:
function (system, app, viewLocator, bindings, extenders, validations) {
//>>excludeStart("build", true);
system.debug(true);
//>>excludeEnd("build");
//Initialize KnockoutJS customizations
bindings.init();
extenders.init();
app.title = 'Some Application';
app.configurePlugins({
router: true,
dialog: true,
widget: true
});
app.start().then(function() {
//Replace 'viewmodels' in the moduleId with 'views' to locate the view.
//Look for partial views in a 'views' folder in the root.
viewLocator.useConvention();
//Show the app by setting the root view model for our application with a transition.
app.setRoot('viewmodels/shell');
});
});
我看不到您在哪里调用viewLocator.useConvention()
,或者自定义viewLocator
还有,你的应用程序目录在哪里?我们有以下目录(在许多其他目录中):
应用程序
观点
视图模型
应用程序位于服务器上Web项目的顶层。除非您直接指定路径或使用自定义viewLocator,否则您需要将视图目录和viewmodels目录放在同一层。换句话说,他们必须是树上的兄弟姐妹 在main.js中查看我们的主要入口点。我已经删除了不相关的部分:
function (system, app, viewLocator, bindings, extenders, validations) {
//>>excludeStart("build", true);
system.debug(true);
//>>excludeEnd("build");
//Initialize KnockoutJS customizations
bindings.init();
extenders.init();
app.title = 'Some Application';
app.configurePlugins({
router: true,
dialog: true,
widget: true
});
app.start().then(function() {
//Replace 'viewmodels' in the moduleId with 'views' to locate the view.
//Look for partial views in a 'views' folder in the root.
viewLocator.useConvention();
//Show the app by setting the root view model for our application with a transition.
app.setRoot('viewmodels/shell');
});
});
我看不到您在哪里调用viewLocator.useConvention()
,或者自定义viewLocator
还有,你的应用程序目录在哪里?我们有以下目录(在许多其他目录中):
应用程序
观点
视图模型
应用程序位于服务器上Web项目的顶层。除非您直接指定路径或使用自定义viewLocator,否则您需要将视图目录和viewmodels目录放在同一层。换句话说,他们必须是树上的兄弟姐妹 在main.js中查看我们的主要入口点。我已经删除了不相关的部分:
function (system, app, viewLocator, bindings, extenders, validations) {
//>>excludeStart("build", true);
system.debug(true);
//>>excludeEnd("build");
//Initialize KnockoutJS customizations
bindings.init();
extenders.init();
app.title = 'Some Application';
app.configurePlugins({
router: true,
dialog: true,
widget: true
});
app.start().then(function() {
//Replace 'viewmodels' in the moduleId with 'views' to locate the view.
//Look for partial views in a 'views' folder in the root.
viewLocator.useConvention();
//Show the app by setting the root view model for our application with a transition.
app.setRoot('viewmodels/shell');
});
});
我看不到您在哪里调用viewLocator.useConvention()
,或者自定义viewLocator
还有,你的应用程序目录在哪里?我们有以下目录(在许多其他目录中):
应用程序
观点
视图模型
应用程序位于服务器上Web项目的顶层。除非您直接指定路径或使用自定义viewLocator,否则您需要将视图目录和viewmodels目录放在同一层。换句话说,他们必须是树上的兄弟姐妹 在main.js中查看我们的主要入口点。我已经删除了不相关的部分:
function (system, app, viewLocator, bindings, extenders, validations) {
//>>excludeStart("build", true);
system.debug(true);
//>>excludeEnd("build");
//Initialize KnockoutJS customizations
bindings.init();
extenders.init();
app.title = 'Some Application';
app.configurePlugins({
router: true,
dialog: true,
widget: true
});
app.start().then(function() {
//Replace 'viewmodels' in the moduleId with 'views' to locate the view.
//Look for partial views in a 'views' folder in the root.
viewLocator.useConvention();
//Show the app by setting the root view model for our application with a transition.
app.setRoot('viewmodels/shell');
});
});
我看不到您在哪里调用viewLocator.useConvention()
,或者自定义viewLocator
还有,你的应用程序目录在哪里?我们有以下目录(在许多其他目录中):
应用程序
观点
视图模型
应用程序是我们在服务器上的Web项目的最高级别。因此,我一直在玩Durandal/Knockout有一段时间了,一开始我也遇到了类似的问题。如果你已经开始在应用程序中使用Knockout,那么所有其他答案都是有用的,而且更相关。但是,因为我在使用Knockout之前就遇到了这个错误,所以我对代码进行了逐行分解 事实证明,我没有在index.html文件中添加div#applicationHost元素。就这样。简单地加上这个就解决了我的问题 index.html
<body>
<div id="applicationHost">
...
</div>
</body>
...
现在,并不一定要始终有一个具有此ID的div,但是您必须手动编写应用程序。你可以阅读更多。所以,我已经玩了一段时间的Durandal/Knockout,在一开始我也遇到了类似的问题。如果你已经开始在应用程序中使用Knockout,那么所有其他答案都是有用的,而且更相关。但是,因为我在使用Knockout之前就遇到了这个错误,所以我对代码进行了逐行分解 事实证明,我没有在index.html文件中添加div#applicationHost元素。就这样。简单地加上这个就解决了我的问题 index.html
<body>
<div id="applicationHost">
...
</div>
</body>
...
现在,并不一定要始终有一个具有此ID的div,但是您必须手动编写应用程序。你可以阅读更多。所以,我已经玩了一段时间的Durandal/Knockout,在一开始我也遇到了类似的问题。如果你已经开始在应用程序中使用Knockout,那么所有其他答案都是有用的,而且更相关。但是,因为我在使用Knockout之前就遇到了这个错误,所以我对代码进行了逐行分解 事实证明,我没有在index.html文件中添加div#applicationHost元素。就这样。简单地加上这个就解决了我的问题 index.html
<body>
<div id="applicationHost">
...
</div>
</body>
...
现在,并不一定要始终有一个具有此ID的div,但是您必须手动编写应用程序。你可以阅读更多。所以,我已经玩了一段时间的Durandal/Knockout,在一开始我也遇到了类似的问题。如果你已经开始在应用程序中使用Knockout,那么所有其他答案都是有用的,而且更相关。但是,因为我在使用Knockout之前就遇到了这个错误,所以我对代码进行了逐行分解 事实证明,我没有在index.html文件中添加div#applicationHost元素。就这样。简单地加上这个就解决了我的问题 index.html
<body>
<div id="applicationHost">
...
</div>
</body>
...