0
我在嘗試實例化我創建的dojo小部件中的類時遇到了主題錯誤: 我有小部件和小部件的html模板名爲/ Templates的目錄。下面是代碼:未捕獲TypeError:對象不是dojo自定義小部件的函數
插件(模板/ Person.js):
define([
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dojo/text!Templates/Person.htm"
],
function (declare, _WidgetBase, _TemplatedMixin, Person) {
return
declare([_WidgetBase, _TemplatedMixin], {
templateString: Person
});
}
);
HTML模板(模板/ Person.htm)
<div>
<p>Bob</p>
<p>Jones</p>
</div>
測試頁(TestPerson.htm)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body class="claro">
<script data-dojo-config="async: 1, dojoBlankHtmlUrl: '/blank.html',
packages: [ {
name: 'Templates',
location: location.pathname.replace(/\/[^/]+$/, '') + '/Templates'
} ]"
src="//ajax.googleapis.com/ajax/libs/dojo/1.10.0/dojo/dojo.js"></script>
<script>
require([
"Templates/Person"
], function (Person) {
var p = new Person();//The object is not function error occurs here
});
</script>
</body>
</html>
任何想法?難道是因爲我在使用CDN?
感謝
萬分感謝。我可以看到它確實有效。我需要繼續使用TestPerson.htm中的位置線: location:location.pathname.replace(/ \/$ /,'') – pvitt 2014-08-28 15:00:13