gpt4 book ai didi

javascript - 使用连接点

转载 作者:行者123 更新时间:2023-12-02 16:39:33 28 4
gpt4 key购买 nike

我是道场新手。我已经创建了小部件并成功执行了它。但现在我想在这里使用附加点的概念。下面是我的代码

练习.html

<div>


</div>

练习.js

define([ "dojo/_base/declare"
, "dojo/text!./practice.html"
, "dijit/_WidgetBase"
, "dijit/_TemplatedMixin"
, "dijit/_WidgetsInTemplateMixin"

], function(declare, _templateString, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin)
{
function trace(msg) {

console.log("practice:", msg, arguments);
}

function Controller(w) {
function myPractice(){
alert("My Practice");
}

this.myPractice = myPractice;
}



var d =
declare("Practice.practice", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
widgetsInTemplate: true,
templateString: _templateString
, constructor: function(args) {
declare.safeMixin(this, args);
},
postCreate: function(){
this.inherited(arguments);
var controller = new Controller(this);
//controller.myPractice();
this.myPractice = controller.myPractice;
}
});
return d;
});

我正在使用 test.html 执行此操作

测试.html

<html >
<head>

<link rel="stylesheet" href="D:/dojofiles/dijit/themes/claro/claro.css">

<script>dojoConfig = {parseOnLoad: true}</script>
<script src="D:/dojofiles/dojo/dojo.js"></script>


<script>

showMyForm = function(){

require(["Practice/practice"],
function(practice){

var myObj = new practice();
myObj.myPractice();
});

}
showMyForm();

</script>


</head>
<body class="claro">

<div id="myId" enctype="multipart/form-data" action="" method="POST">

</body>
</html

在哪里以及如何添加 data-dojo-attach-point 并使用它来执行我的小部件?

最佳答案

如果您开始使用其他 HTML 节点扩展您的小部件模板 (practice.html),并且您希望从 JavaScript 小部件代码 (practice.js )然后您使用附加点,例如:

练习.html

<div>
<input type="text" data-dojo-attach-point="textfield" />
</div>

practice.js

var d = declare("Practice.practice", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
widgetsInTemplate: true,
templateString: _templateString,
constructor: function(args) {
declare.safeMixin(this, args);
},
someFunction: function() {
console.log(this.textfield.value); // Now you can use this.textfield thanks to the attach point
},
postCreate: function(){
this.inherited(arguments);
var controller = new Controller(this);
//controller.myPractice();
this.myPractice = controller.myPractice;
}
});

但是,我不太确定您是否熟悉 data-dojo-attach-point 的概念,因为说实话,它不会执行您的小部件。

关于javascript - 使用连接点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27624004/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com