gpt4 book ai didi

krl - 奇怪的 KRL foreach 行为

转载 作者:行者123 更新时间:2023-12-04 05:32:55 24 4
gpt4 key购买 nike

我今天使用 foreach 遇到了一些奇怪的行为。我有一个 dataset这是在拉入一个 JSON 文档。它的一部分是一个数组,我 pick() out 并发送到 foreach。这是我的全局块:

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

这是不起作用的规则:
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

任何想法这里发生了什么?

最佳答案

您的 html 结构和用于插入新内容的后选择器存在递归问题。

您插入新内容的选择器是

#462popular .image

这意味着 html 的内容将被插入到每个具有图像类的元素之后,该元素包含在 id 为 #462popular 的元素中。

在您插入的 html 中,您有一个类名为 image 的元素,这意味着每次遍历循环时,您都将元素数量与 #462popular 中的图像类相乘。

:)

关于krl - 奇怪的 KRL foreach 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4982168/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com