외부 함수의 인수 'parent'에 액세스하는 방법 ??? 코드 에있는 의견을 참조하십시오 !!
최종 편집 :가변 범위 mootools
array.each(function(el) {
this.method(); // this == (instance/scope)
}, this); // where **this** is your parent scope.
다른 허용 방법은 다음과 같습니다 :이 질문은 내 문제가 각 루프 내 잘못 입력 인수
renderData : function(parent, children){
children.each(function(e, index){
var li = new Element('li');
var hasChildren = false;
if(e.children && e.children.length >0){
var img = new Element('img');
img.src = 'a1.png';
img.inject(li);
hasChildren = true;
}
if(e.icon){
var img = new Element('img');
img.src = e.icon;
img.inject(li);
}else{
var img = new Element('img');
img.src = 'b1.png';
img.inject(li);
}
li.set('html',e.text);
console.log(this);
// how to access outer function's argument 'parent' ???
li.inject(parent);
if(hasChildren){
var ul = new Element('ul');
this.renderData(ul, e.childRen);
ul.inject(e);
}
}.bind(this));
다른 문제로 인해서 죄송합니다. – kuangfuking