我正在构建一个使用rss feed的交互式地图。地图本身是在SVG和每个检查点中创建的。具有circle
的类,并且递增为circle+k
(circle1,circle2,circle3等)。我的RSS Feed将确定上述圈子中有多少会获得filled
类,以填充其颜色。
我正在以编程方式执行上述操作,其中我运行2个函数来递增每个div,如下所示:
//increments circle class on the map's dots
$("#map .circle").each(function(k) {
$(this).addClass("circle" + (k + 1));
});
//increments step class on the rss-fed items
$(".gs-rss-feed .hs-rss-item").each(function(i) {
$(this).addClass("step" + (i + 1));
//if circle class + number = step class + number, add class filled to circle
$("#map .circle").eq(i).addClass("filled");
});
但是现在我需要做额外的事情,从每个RSS帖子(title
和url
)访问某些信息。这些都是在课堂上完成的,所以我应该能够得到他们的信息:
//Get link from html
var link = $('.hs-rss-title').attr('href').split('=');
//Get title
var title = $('.hs-rss-title span').html();
然后我需要使用.wrap();
我遇到问题的问题是,如何将每个变量(title
和url
)范围扩展到每个特定点。如果我使用上面保存变量的方法,那么尝试使用$("#map .circle").eq(i).wrap("<a href="+link+"></a>");
它最后只附加第一个例子,即:将第一个RSS项的url添加到地图上的每个点。
他们可以更好地解决这个问题吗?这是我的 codepen ,欢迎任何帮助!
答案 0 :(得分:1)
我还没有足够的声誉发表评论,所以我不得不将此作为答案发布..
你不能在第二天内完成这项工作吗?
//increments step class on the rss-feed items
$(".gs-rss-feed .hs-rss-item").each(function(i) {
var $rss-item = $(this);
$rss-item.addClass("step" + (i + 1));
//if circle class + number = step class + number, add class filled to circle
var $circle = $("#map .circle").eq(i);
$circle.addClass("filled");
//Get link from html
var link = $rss-item.find('.hs-rss-title').attr('href').split('=');
//Get title
var title = $rss-item.find('.hs-rss-title span').html();
// here you can wrap $circle and do whatever you want with this link and title
});
并不是真的与你的问题有关,但你为什么要把你的href拆分=?除了遗漏一些斜线之外,我在给定的href属性中看不到需要将其拆分为=的任何内容。