Dojo 似乎无法解析在自定义小部件的模板 html 文件中以声明方式创建的小部件。
但是当我在完成 dojo 配置的主页中以声明方式创建它时,它会起作用
这是代码片段:
首页:
<html>
<head>
<script type="text/javascript">
var dojoConfig = {
parseOnLoad: true,
isDebug: true,
modulePaths : {"com.cgb":"../../../client/vtm/com/cgb"}
};
</script>
<script type="text/javascript" src="../common/dojo/dojo/dojo.js"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("com.cgb.modules.deposit.step1_agreement");
dojo.require("dojox.mobile.ScrollableView");
</script>
</head>
<body>
<div data-dojo-type="com.cgb.modules.deposit.step1_agreement"></div>
</body>
</html>
自定义小部件:
dojo.provide("com.cgb.modules.deposit.step1_agreement");
dojo.require("dojo.cache");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("dojox.mobile.ScrollableView");
dojo.declare("com.cgb.modules.deposit.step1_agreement", [dijit._Widget, dijit._Templated], {
templateString: dojo.cache("com.cgb.modules.deposit", "templates/step1_agreement.html"),
postCreate:function(){
console.log("widget get instantiated");
}
});
自定义小部件的模板 html:
<div>
<!--this widget didn't get parsed -->
<div id="view1" dojoType="dojox.mobile.ScrollableView" height="50px">
blah blahblah blah<br/>blah blahblah blah<br/>blah blahblah blah<br/>
blah blahblah blah<br/>blah blahblah blah<br/>blah blahblah blah<br/>
blah blahblah blah<br/>blah blahblah blah<br/>blah blahblah blah<br/>
</div>
</div>
ScrollableView 小部件没有得到解析,但是当我在主页上声明它时它可以工作。我想也许我一定错过了什么,请帮助我。
最佳答案
由于您使用的是 dojox.mobile,您的代码可能处于语法中间。
http://dojotoolkit.org/documentation/tutorials/1.7/modules/#Defining_modules
对于 future 的版本,如果您在模板中使用小部件,则参数 widgetsInTemplate: true
将被弃用。反过来,将 dijit._WidgetsInTemplateMixin
作为模块的混合包含在内。
例如; <1.7
dojo.provide("com.cgb.modules.deposit.step1_agreement");
dojo.require("...");
dojo.declare("com.cgb.modules.deposit.step1_agreement", [dijit._Widget, dijit._Templated], {
widgetsInTemplate: true,
templateString: dojo.cache("com.cgb.modules.deposit", "templates/step1_agreement.html"),
postCreate:function(){
console.log("widget get instantiated");
}
});
和1.7+(期望模块将文件名/路径作为模块和命名空间)
define([ "dojo/_base/declare", "dijit/_WidgetBase", "dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin" ], // note latter mixin
function(declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin){
return declare([ _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin ], {});
});
关于javascript - Dojo 不解析自定义小部件的模板 html 中的小部件声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12420281/