我已經構建了一個通過輸入值創建列表的Dojo小部件。小部件代碼是: define(["dojo/_base/declare", "dijit/_WidgetBase", "dijit/_TemplatedMixin", 'dojo/text!apps/orders/templates/multiAddList.html', "dojo/dom", "dojo/on", "dojo/dom-construct", "dojo/dom-class", "dojo/query", "dijit/focus"],
相同小部件的Dojo實例沒有分解
function (declare, WidgetBase, TemplatedMixin, html, dom, on, domConstruct, domClass, query, focusUtil) {
return declare([WidgetBase, TemplatedMixin], {
templateString: html,
postCreate: function() {
this.inherited(arguments);
var that = this;
},
_checkIfEnter: function (e) {
if (e.which == 13) {
this._addUser();
}
},
_addUser: function() {
domClass.remove(this.ulAdded, "hidden");
var textToAdd = this.userTextToAdd.value;
var li = domConstruct.create("li", {}, this.ulAdded);
domConstruct.create("span", {innerHTML: textToAdd}, li);
var spanX = domConstruct.create("span", {class: 'icon-x right'}, li);
this.itemsArray.push(textToAdd);
this.userTextToAdd.value = "";
focusUtil.focus(this.userTextToAdd);
var that = this;
on(spanX, "click", function() {
domConstruct.destroy(li);
that.itemsArray.splice(that.itemsArray.indexOf(textToAdd), 1);
if (that.itemsArray.length == 0) {
domClass.add(that.ulAdded, "hidden");
}
});
},
itemsArray: []
});
});
這一切都OK。但是 - 當我實例兩次在同一個對話是這樣的:
allowedDomains = new MultiAddList();
allowedDomains.placeAt(dom.byId('allowedDomains'), 0);
pdlEmails = new MultiAddList();
pdlEmails.placeAt(dom.byId('pdlEmails'), 0);
,然後要求allowedDomains.itemsArray()或pdlEmails.itemsArray() - 我得到相同的列表(如果是同一個實例) - 儘管在用戶界面演示文稿中 - 他分別正確地添加了列表項。
顯然,儘管我遵循了Dojo的示例,但我做錯了什麼。
有沒有人知道我應該怎麼做才能使它工作?
感謝
有關此行爲的相關dojo文檔可以在http://dojotoolkit.org/reference-guide/1.9/dojo/_base/declare.html#id6標題下找到,數組和對象作爲成員變量' – BuffaloBuffalo
謝謝! =)總是有用的東西回來鏈接,對不起,我原本太懶了。 –
太棒了!謝謝! – Assaf