我正在使用durandal js入门工具包应用程序,在某个时刻,当我在Mozilla浏览器中查看页面源代码时,看到了以下内容。
<div class="" data-view="views/shell" style="" data-active-view="true"> </div>
我在任何地方都找不到
data-view
属性的作用。这是durandal js,其他任何javascript库或html本身使用的自定义属性吗? 最佳答案
我想您的问题的答案是这样的:
该属性允许Durandal跟踪相对于应用程序的root
目录位于何处的视图。data-view="views/shell"
基本上让Durandal知道shell.html
模板(视图)位于views/
目录中,并且每当触发完整的应用程序刷新时,Durandal就会知道从何处提取此精确视图。 shell
视图基本上表示Web应用程序的外壳。
这是重新加载应用程序/单击Flickr选项卡时的日志:
Debug:Enabled
Application:Starting
Plugin:Installed plugins/router
Plugin:Installed plugins/dialog
Application:Started
XHR finished loading: GET "http://localhost:8000/app/views/shell.html".
Navigation Complete ctor {displayName: "Welcome to the Durandal Starter Kit!", description: "Durandal is a cross-device, cross-platform client … Applications (SPAs) easy to create and maintain.", features: Array[11], __moduleId__: "viewmodels/welcome"} Object {fragment: "", queryString: null, config: Object, params: Array[0], queryParams: null}
Binding views/shell Object {router: Object, search: function, activate: function, __moduleId__: "viewmodels/shell"}
XHR finished loading: GET "http://localhost:8000/app/views/welcome.html".
Using CSS3 animations.
Binding views/welcome ctor {displayName: "Welcome to the Durandal Starter Kit!", description: "Durandal is a cross-device, cross-platform client … Applications (SPAs) easy to create and maintain.", features: Array[11], __moduleId__: "viewmodels/welcome"}
看到那些“ XHR完成加载”消息吗?那是Durandal通过从
data-view
属性获取路径来加载视图的地方。单击“ Flickr”选项卡,将为我们提供以下内容:
Activating Object {displayName: "Flickr", images: function, activate: function, select: function, canDeactivate: function…}
Navigation Complete Object {displayName: "Flickr", images: function, activate: function, select: function, canDeactivate: function…} Object {fragment: "flickr", queryString: null, config: Object, params: Array[0], queryParams: null}
XHR finished loading: GET "http://localhost:8000/app/views/flickr.html".
Binding views/flickr Object {displayName: "Flickr", images: function, activate: function, select: function, canDeactivate: function…}
请参阅“ XHR完成加载... views / flickr.html”-再次查询
data-view
属性以获取视图路径,并通过AJAX检索视图。希望这能为您清除一切。
关于javascript - 什么是Durandal JS中的数据 View 属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29443350/