2012-10-22 7 views
0

각각 내부에서 함수를 호출 할 수 있습니다. 객체의jQuery 템플릿, 각 내부의 owne 함수 호출

I 한 배열 :

Object { 
    array = new Array(), //{ true, true, false } 
    areAllTrue = function(){ 
    //check if true code 
    } 
} 

나는이를 호출해야합니다

{{each Array}} 
    ${$value.areAllTrue()} 
{{/each}} 

그리고 그것은 단지 마지막 개체에 대해 작동합니다.

답변

0

코드 중 구문 적으로 올바른 코드가 없기 때문에 실제로 시도하고있는 내용이 다소 모호합니다. 나는 당신이 아래의 코드를 사용한다는 것을 단지 추측 할 수 있습니다.

//you have an array of objects, where each has a function 
var objArray = [ 
    { 
    objFunc: function(){ 
     return 'objArray #0 objFunc'; 
    } 
    }, 
    { 
    objFunc: function(){ 
     return 'objArray #1 objFunc'; 
    } 
    }, 
    { 
    objFunc: function(){ 
     return 'objArray #2 objFunc'; 
    } 
    } 
]; 

//you need to call each function of all objects 
//in the array via jQuery "each" method. 
$.each(objArray, 
    function(idx, itm){ 
    //"itm" is the array item, which is the object 
    var a = itm.objFunc(); //call it 
    //log the result. see web browser Console 
    console.log(a); 
    } 
); 
+0

모두 괜찮습니다. 내 타입의 모든 객체가 Object 타입으로 변환되고 나서 내 타입의 새로운 객체를 추가하고 나면 JSON에서 이것을 얻는다. –