gpt4 book ai didi

javascript - DOJO dijit/registryregistry.byId() 不监视小部件?

转载 作者:行者123 更新时间:2023-12-03 11:13:12 26 4
gpt4 key购买 nike

我需要查看registry.byId ( http://dojotoolkit.org/reference-guide/1.10/dijit/registry.html ) 返回的小部件。

我可以从registry.byId获取引用,但观察其属性不起作用。知道如何解决这个问题吗?

http://jsfiddle.net/5rpjby7j/

    <span data-dojo-type="BusinessCard"></span>
<span data-dojo-type="BusinessCard"></span>


window.State = {
name: 'state: name',
surname: 'state: surname',
custom: 'state: custom',
custom2: 'state: custom2'
};

window.FactoryProperties = function () {
// here you can add private members (closure)
// return an object with common properties for wpis
return {
custom: window.State.custom, // data taken dynamically from state
_setCustomAttr: function (value) {
this.custom = value;
window.State.custom = value;
this.customNode.innerHTML = window.State.custom;
},
custom2: window.State.custom2,
_setCustom2Attr: function (value) {
this.custom2 = value;
window.State.custom2 = value;
this.customNode2.innerHTML = window.State.custom2;
}
};
};

require([
"dojo/_base/declare", "dojo/parser", "dojo/ready",
"dijit/_WidgetBase", "dijit/_TemplatedMixin", "dojo/_base/lang", "dijit/registry"
], function (declare, parser, ready, _WidgetBase, _TemplatedMixin, lang, registry) {
// properties custom for wpi
var prop1 = {
templateString: "<div class='businessCard'>" +
"<div>NAME : <span data-dojo-attach-point='nameNode'></span></div>" +
"<div>SURNAME : <span data-dojo-attach-point='surnameNode'></span></div>" +
"<div>CUSTOM: <span data-dojo-attach-point='customNode'></span></div>" +
"<div>CUSTOM2: <span data-dojo-attach-point='customNode2'></span></div>" +
"<br>" +
"</div>",

name: window.State.name,
_setNameAttr: function (value) {
window.State.name = value;
this.name = value;
this.nameNode.innerHTML = window.State.name;
},

surname: window.State.name,
_setSurnameAttr: function (value) {
window.State.surname = value;
this.surname = value;
this.surnameNode.innerHTML = window.State.surname;
}
};
var propTot = lang.mixin(prop1, window.FactoryProperties());
declare("BusinessCard", [_WidgetBase, _TemplatedMixin], propTot);

ready(function () {
parser.parse();
// watch a widget PROBLEM HERE
var mywidget = registry.byId("BusinessCard_1");
mywidget.watch("name", function () {
alert('name have been updated!!!!!!!!!!!');
});

registry.byId("BusinessCard_1").set("name", 'MODIFIED name from code');
registry.byId("BusinessCard_1").set("custom", 'MODIFIED surname from code');
//registry.byId("BusinessCard_1").set("custom2", 'CUSTOM2 MODIFIED PROGRAMMATICALLY');
console.log(registry.toArray()); // check the registry
console.log(registry.byId("BusinessCard_1"));

});
});

最佳答案

此处已修复 http://jsfiddle.net/5rpjby7j/1/

使用 _setSurnameAttr() 中的 this._set("surname", value) 解决

            _setSurnameAttr: function (value) {
window.State.surname = value;
this._set("surname", value)
this.surnameNode.innerHTML = window.State.surname;
}

有用的帖子 http://dojo-toolkit.33424.n3.nabble.com/watch-on-custom-widget-not-firing-td3997554.html

关于javascript - DOJO dijit/registryregistry.byId() 不监视小部件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27460755/

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