0
我沒有在文檔中找到如何從嵌套的require塊中訪問類的方法的局部變量。在嵌套的require塊中訪問局部變量/方法?
declare("Clust", StrictIntHashMap,
{
constructor : function()
{
},
cust : function(custId)
{
return this.get(custId);
},
add : function(custObject)
{
this.set(custObject.custId, custObject);
},
reloadThecustses : function()
{
that = this;
require([ 'inst/DataExtractor', 'inst/ClustTree' ], function (de, theTree)
{
de.getPlainJSON(Commandz.COMMAND_GET_CUSTS,
function (dataR)
{
that.add(new Customer(dataR.root[c])); // not working
this.cust(0); // not working
theTree.refreshTheData(dataR.root);
});
});
}
});
return Clust;
- 如何訪問該方法從需要塊內的類的「添加」?
- 如何從require塊中訪問本地變量「that」?
你運行什麼確切的測試代碼來聲明它「不工作」? – Louis
Custs.js:60 Uncaught ReferenceError:沒有定義,如果我刪除它並將其替換爲「this.add(whatever)」,它會變爲「Custs.js:61 Uncaught TypeError:無法讀取屬性'add'undefined 「 –
但是''''是在你的代碼中定義的。你用'that = this'來定義它。你應該真的有'var that = this',因爲如果沒有'var',你把它放在全局空間中,這是不好的編碼,但它*是*定義的。 – Louis