私は、別のAMDjsユニット内で宣言され、定義されたオブジェクトのメソッドを呼び出そうとしています。別のAMDjsユニットからオブジェクトのメソッドを呼び出す?
最初単位:
define([ .. 'XTree' ], function(.. xTree)
{
...
var btnX = document.createElement('input');
btnX.type = 'button';
btnX.value = 'hey';
btnX.style.width = '90px';
btnX.style.height = '25px';
btnX.onclick = function () { xTree.fire() };
...
});
-
:
- ボタンをクリックする理由結果x fire()メソッドをトリガーするのではなく、ツリーが定義されていませんか?
require(
[
"dojo/ready",
"dojo/store/Memory", \t \t \t \t
"cbtree/Tree", \t \t \t \t \t \t
"cbtree/model/TreeStoreModel", \t
"dojo/dom-class",
"dojo/domReady",
"dijit/form/CheckBox",
"dojo/domReady!"
],
function
(
ready,
Memory,
Tree,
ObjectStoreModel,
domClass,
CheckBox
)
{
var XTree = function()
{
this.store = new Memory({ data: this.datax() });
this.model = new ObjectStoreModel(
{
store: this.store,
query: { id: "all" },
rootLabel: "xxx",
checkedRoot: true
});
}
XTree.prototype.applyTheTree = function()
{
this.tree = new Tree({ model: this.model, id: "tree00", animation: false }, "treeViewx");
this.tree.startup();
}
XTree.prototype.fire = function()
{
alert('fire');
}
XTree.prototype.datax = function()
{
return [
{ id: 'all', name:'' },
{ id: 'br1', name:'branch 1', parent: 'all' },
{ id: '1', name:'b 1', parent: 'br1' },
{ id: '1', name:'b 2', parent: 'all' }
]
};
var xTree = new XTree();
ready(function()
{
xTree.applyTheTree();
});
return xTree;
});
Iが第二ユニット内でこのような別の装置からオブジェクトを参照しようとここ は、例えば、コードです
何らかの理由で似ているようですが、現時点では私の二次モジュールのユニットを参照しています。それはコンストラクタをうまく通過します。 –
欠けている部分はシングルトンそのものでした。魅力的な作品! –