gpt4 book ai didi

javascript - 使用 Jquery 过滤解析的 csv 数据

转载 作者:行者123 更新时间:2023-12-03 08:52:57 24 4
gpt4 key购买 nike

我使用此代码来指定要获取哪些数据以及如何将其添加到我的 HTML 中。

window.onload = (function(CMS) {
//parse your csv file
Papa.parse("LINK", {
download: true,
complete: function(results) {
console.log(results);
$.each(results.data.slice(1), // skip first row of CSV headings
function(find, data) {
var title = data[0];
var link = data[4];
var date = data[2];
var type = data[3];
$('ul.nflist').append($('<li>', {
html: '<a href="' + link + '">' + title + '</a> ' + ' ' + '<span class="category">' + type + '</span>'
}));
});
//weird issue with an empty line.. just delete the last <li>
$('ul.nflist li:last-child').remove();
//Now that your data is clean and in its proper place you can begin to do the preety stuff like add images to corresponding categories
//First hide the category tag...
$(".category").hide();
// Now lets search for categories and add images
$('ul.nflist li:contains("sm")').prepend('<img src="http://www.jonar.com/portal/partner/img/sendemailo.png" />');
$('ul.nflist li:contains("blog")').prepend('<img src="http://www.jonar.com/portal/partner/img/bello.png" />');
$('ul.nflist li:contains("ann")').prepend('<img src="http://www.jonar.com/portal/partner/img/calendaro.png" />');
$('ul.nflist li:contains("itp")').prepend('<img src="http://www.jonar.com/portal/partner/img/pluscircleo.png" />');
}
});

});

解析 csv 时,json 文件如下所示:

[
{
"title": "Choice, Happiness and Spaghetti Sauce",
"summary_text": "Delivering product variety: chunky spaghetti sauce, zesty pickles, or weak coffee? Gladwell explains how the root of happy customers is product variety.",
"date": "30-Jan-13",
"type": "sm",
"link": "https://www.facebook.com/permalink.php?id=380939405308665&story_fbid=298838986905013"
},
{
"title": "Servoy Interviewed Us",
"summary_text": "Servoy interviewed our managing director,Jon Ruby. Find out why we chose Servoy and learn about our development best practices.",
"date": "4-Nov-14",
"type": "itp",
"link": "https://plus.google.com/+ServoyPlus/posts/aUL28cD2hfH"
},
{
"title": "Come Together, Right Now: The Benefits of Cross-Functional Teams",
"summary_text": "What do you get when you put an engineer, a doctor and a lawyer in one room? Find out how to create an environment to sustain cross-functional teams.",
"date": "2-May-13",
"type": "blog",
"link": "http://www.jonar.com/jonarblog/come-together-right-now-the-benefits-of-cross-functional-teams/"
},
{
"title": "What is ERP?",
"summary_text": "The acronym, �ERP� is tossed around constantly, but what does it actually mean for your business?",
"date": "25-Aug-11",
"type": "sm",
"link": "https://www.youtube.com/watch?v=PVRgIXLWDHs"
},
{
"title": "Admit You Don�t Know � Take The Road Less Traveled",
"summary_text": "If you�ve ever felt like a fraud, you�re not alone. Instead of ignoring it, here�s why you should embrace the experience of Imposter Syndrome.",
"date": "17-Oct-14",
"type": "blog",
"link": "http://www.jonar.com/jonarblog/admit-you-dont-know-take-the-road-less-travelled/"
},
{
"title": "Jonar is Looking to Build Our Network of VAP�s",
"summary_text": "Jonar has started building an international network of partners. Want in? Join us on our journey to reinvent ERP.",
"date": "no date",
"type": "ann",
"link": "http://www.jonar.com/new/signUp.html"
},
{
"title": ""
}

]

这是一些具有 sm 的类型的问题。我不想要这些行...假设类型 sm 它不应该包含该行..我如何过滤数据?

最佳答案

使用这个

       $.each(results.data.slice(1), // skip first row of CSV headings
function(find, data) {
if(data.type !="sm") {
var title = data.title;
var link = data.link;
var date = data.date;
var type = data.type;
}
}
);

关于javascript - 使用 Jquery 过滤解析的 csv 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32617234/

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