2011-02-13 3 views
4

저는 foreach를 사용하여 이상한 행동을하고 있습니다. JSON 문서를 가져 오는 dataset이 있습니다. 배열의 부분은 내가 pick()이며 foreach로 보냅니다. 내 글로벌 블록은 다음과 같습니다.이상한 KRL foreach 동작

global { 
    dataset appserver <- "http://imaj-app.lddi.org:8010/list/popular" cachable for 1 hour; 
    popular = appserver.pick("$..images") 
} 

먼저 페이지를 설정하는 규칙이 하나 있습니다. (스크롤 엄지가 얼마나 작은 알)

rule images { 
    select when web pageview "www\.google\.com" 
    foreach popular setting (image) 

    pre { 
    thumburl = image.pick("$..thumburl"); 
    viewurl = "http://imaj-web.lddi.org/view?imagekey=" + image.pick("$..imagekey"); 
    html = << 
     <span class="image"><a href="#{viewurl}"><img src="#{thumburl}" style="border:none"/></a></span> 
    >>; 
    } 

    after('#462popular .image', html); 
} 

나는 이런 식으로 뭔가를 얻을 :

Lots of images

은 다음과 같습니다

rule setup { 
    select when web pageview "www\.google\.com" 

    pre { 
    imagelist = << 
     <div id="462popular" style="margin-left:auto;margin-right:auto;width:450px"> 
     <p>Popular images from the CS 462 <a href="http://imaj-web.lddi.org/">Image Project</a></p> 
     <span class="image"></span> 
     </div> 
    >>; 
    } 

    prepend('#footer', imagelist); 
} 

을 그리고 여기에 작동하지 않는 규칙입니다

아이디어가 어떻게되고 있습니까?

답변

3

html 구조와 애프터 선택 자의 재귀 문제로 인해 새 콘텐츠를 삽입 할 수 있습니다. 새로운 콘텐츠를 삽입

내 선택기 html의 내용 # 462popular의 ID와 내측 요소 화상의 종류와 각 요소 뒤에 삽입 될 것임을 의미

#462popular .image 

이다.

삽입하려는 html 안에는 이미지의 클래스 이름을 가진 요소가 있습니다. 즉, 루프를 통과 할 때마다 이미지 수의 클래스에 # 462popular의 수를 곱하는 것을 의미합니다.

:)

+0

오! 나는 그것을 알아야했다. :) –