我想分配給每個類別的職位列表和顯示與塞作爲鏈接標題,只顯示文章中,我不想硬編碼的類別名稱,而是希望抓住分配給每個類別的每個帖子。我希望這是有道理的。JSON:一類鏈接上點擊時,我想在這一類
我的問題是,我怎麼比較,如果該職位是類別塞「全合格,退休計劃」的一部分?
我想要做的是......當我點擊鏈接「#全部合格退休計劃」時,我只希望那些職位顯示與類別slu「」全合格退休計劃「
<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)
那麼,什麼是你的問題? – Areca
代碼不起作用 – velvetInk
不知道你想幫什麼,但可以考慮使用一個模板引擎像這樣的東西,所以你不必做所有的字符串連接東西,這是保持一個噩夢。例如:http://handlebarsjs.com/ –