[英]jQuery.each variable scope
I have the following problem: 我有以下问题:
var loader = new THREE.JSONLoader( true );
model = JSON.parse(data);
var modeldata = loader.parse( jQuery.parseJSON(model['value1']) );
...
var modeldata = loader.parse( jQuery.parseJSON(model['value2']) );
...
WORKS FINE. 工作正常。
var loader = new THREE.JSONLoader( true );
model = JSON.parse(data);
jQueryX.each(parts, function(key, value){
var modeldata = loader.parse( jQuery.parseJSON(model[value]) );
...
});
returns 'model is undefined' 返回“模型未定义”
Is there a scope problem? 有范围问题吗? I can not see any... 我看不到...
Expert advices welcome... 欢迎专家咨询...
I am not sure about this. 我对此不确定。 parts contains the list of keys (in parts[value]) that are used in model. parts包含模型中使用的键列表(在parts [value]中)。 In other words, the key of model is the value of parts. 换句话说,模型的关键是零件的价值。
You need to just use jQuery.parseJSON(model[key])
您只需要使用jQuery.parseJSON(model[key])
jQueryX.each(parts, function(key, value) {
modelData = loader.parse(jQuery.parseJSON(model[key]));
});
key
is the key by which you get the value. key
是获取价值的钥匙。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.