json:当点击一个类别链接时,我想只显示该类别中的帖子
json: when clicking on a category link I want to display only posts in that category
我想获得分配给每个类别的帖子列表,并用slug作为链接显示标题,我不想硬编码类别名称,而是想获取分配给每个分类的每个帖子。我希望这是有道理的。
我的问题是,如果这个职位属于"所有合格的退休计划"类别,我该如何比较?
我想做的是…当我点击链接"#所有符合条件的退休计划"时,我只想让这些帖子显示为"所有符合条件退休计划"类别
<ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset ui-corner-all ui-shadow">
<li data-id="4" data-parent="1" class="ui-first-child">
<a href="#all-qualified-retirement-plans" class="ui-btn ui-btn-icon-right ui-icon-carat-r">All Qualified Retirement Plans</a></li>
<li data-id="7" data-parent="0" class="ui-first-child">
<a href="#fica-ss-medicare-taxes" class="ui-btn ui-btn-icon-right ui-icon-carat-r">FICA - SS & MEDICARE TAXES</a></li>
<li data-id="2" data-parent="0">
<a href="#healthcare-plans" class="ui-btn ui-btn-icon-right ui-icon-carat-r"/> Healthcare Plans </a></li>
<li data-id="3" data-parent="0">
<a href="#other-benefits" class="ui-btn ui-btn-icon-right ui-icon-carat-r">Other Benefits</a></li>
</ul>
function allQualifiedRetirementPlans(data) {
"use strict";
var output = '<ul data-role="listview" data-filter="true" data-filter-placeholder="Search..." >';
$.each(data.posts, function(key, val) {
output += '<li>';
output += '<a href="#' + val.slug + '">'; // post slug
output += '<h3>' + val.title + "</h3>"; // post title
output += '</a>';
output += '</li>';
}); //go through each post
output += "</ul>";
$('#all-qualified-retirement-plans-postlist').html(output);
//json
var data = {
"status": "ok",
"count": 24,
"count_total": 24,
"pages": 1,
"posts": [
{
"id": 131,
"type": "benefits",
"slug": "highly-compensated-employee-hce",
"url": "http://mywebsite.com/benefits/highly-compensated-employee-hce/",
"status": "publish",
"title": "Highly Compensated Employee (“HCE”)",
"title_plain": "Highly Compensated Employee (“HCE”)",
"content": "<p>Qualified Retirement Plans must not favor Highly Compensated Employees (HCEs). HCEs are used in testing for discrimination, such as testing employee and employer contributions under a 401(k) plan. An HCE is one who either: a) owns more than 5% of the organization, either directly or indirectly, no matter what that person’s pay is, or b) any employee whose pay from the organization, for the previous year, exceeds the amount shown below.</p>'n",
"excerpt": "<p>Qualified Retirement Plans must not favor Highly Compensated Employees (HCEs). HCEs are used in testing for discrimination, such as testing employee and employer contributions under a 401(k) plan. An HCE is one who either: a) owns more than 5% of the organization, either directly or indirectly, no matter what that person’s pay is, or b) … <a href='"http://mywebsite/benefits/highly-compensated-employee-hce/'" class='"more-link'">Continue reading<span class='"screen-reader-text'"> “Highly Compensated Employee (“HCE”)”</span></a></p>'n",
"date": "2016-04-01 18:06:34",
"modified": "2016-04-01 18:06:54",
"categories": [
{
"id": 4,
"slug": "all-qualified-retirement-plans",
"title": "All Qualified Retirement Plans",
"description": "",
"parent": 1,
"post_count": 4
},
{
"id": 1,
"slug": "retirement-plans",
"title": "Retirement Plans",
"description": "",
"parent": 0,
"post_count": 13
}
],
"tags": [],
"author": {
"id": 1,
"slug": "keith",
"name": "keith",
"first_name": "",
"last_name": "",
"nickname": "keith",
"url": "",
"description": ""
},
"comments": [],
"attachments": [],
"comment_count": 0,
"comment_status": "closed",
"custom_fields": {
"extra_content_extra_content_title": [
""
],
"extra_content_extra_content_medicare": [
""
],
"extra_content_extra_content_percent_moved": [
" "
],
"extra_content_extra_content_percent_value": [
""
],
"extra_content_extra_content_first_value": [
"2016: 120,000"
],
"extra_content_extra_content_second_value": [
"2015: 120,000"
],
"extra_content_extra_content_third_value": [
"2014: 115,000"
],
"extra_content_extra_content_fourth_value": [
"2013: 115,000"
],
"extra_content_extra_content_firth_value": [
"2012: 115,000"
],
"extra_content_extra_content_sixth_value": [
"2011: 110,000"
],
"extra_content_extra_content_seventh_value": [
"2010: 110,000"
],
"extra_content_extra_content_eight_value": [
""
],
"extra_content_extra_content_nine_value": [
""
],
"extra_content_extra_content_ten_value": [
""
],
"social_security_social_security_title": [
""
],
"social_security_social_security_field_one": [
""
],
"social_security_social_security_field_two": [
""
],
"social_security_social_security_field_three": [
""
],
"social_security_social_security_field_four": [
""
],
"social_security_social_security_field_five": [
""
],
"social_security_social_security_field_six": [
""
],
"social_security_social_security_field_seven": [
""
],
"social_security_social_security_field_eight": [
""
],
"social_security_social_security_field_nine": [
""
],
"social_security_social_security_field_ten": [
""
],
"extra_content_three_title": [
""
],
"extra_content_three_field_one": [
""
],
"extra_content_three_field_two": [
""
],
"extra_content_three_field_three": [
""
],
"extra_content_three_field_four": [
""
],
"extra_content_three_field_five": [
""
],
"extra_content_three_field_six": [
""
],
"extra_content_three_field_seven": [
""
],
"extra_content_three_field_eight": [
""
],
"extra_content_three_field_nine": [
""
],
"extra_content_three_field_ten": [
""
]
}
}
};
allQualifiedRetirementPlans (data)
看起来好像在数据对象的"posts"
字段中缺少关闭的]
。
更新
我还包含了在类别上循环的逻辑,以查看对象数组中是否存在段塞。
此外,为了表明简单循环不需要jQuery,我删除了$.each()方法
看看这把小提琴:https://jsfiddle.net/5yyg3req/2/
相关文章:
- Jquery在初始页面加载时选中复选框时显示链接的代码
- 当主导航链接悬停时,在侧菜单中显示链接
- 悬停时无法单击锚标记,但其显示链接
- 如何通过mailto在电子邮件中突出显示链接
- 如何在第一次点击时突出显示链接;并在第二次单击时跟随它,除非在其他地方单击,然后重新初始化未高亮显示的状态
- 希望仅为已登录的用户显示链接,否则它显示该链接在AngularJS和NodeJS中被隐藏或禁用
- 点击提交按钮后如何显示链接
- 如何使用 JavaScript 在共享按钮中显示链接
- 如何制作一个按钮,当悬停在上面时,会滑动并显示链接 (JS)
- 有条件地以角度显示链接.js
- JavaScript 函数不显示链接地址
- 显示链接的内容
- 在UI中显示链接函数angularJs的数据
- J汤html解析样式=“;显示:无;不要显示链接
- 将逻辑与幻灯片和隐藏/显示链接起来
- 可以在我的网站的另一个网站的地址栏中显示链接吗
- 如果低于特定的浏览器宽度,请不要显示链接
- 使用javascript在if条件内显示链接
- 如何在文本框中显示链接,并让按钮将其保存到数据库中
- 当用户单击“显示链接”时,显示密码,再次单击时将其隐藏