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