我有一個ajax GET請求,通過循環拉入數據。我試圖實現的是獲取相關的帖子,但不在當前發佈的預定義ID值中。所以,我有下面這個函數:如果對象關鍵字等於預定義值,如何追加json數據?
var _permId = $('#work-area').data('current-id');
var getRelatedPosts = function() {
$.ajax({
url: '/wp-json/posts?type=case-studies&filter[taxonomy]=awards&filter[term]='+_awardsPart+'',
success: function (query) {
//List some global variables here to fetch post data
// We use base as our global object to find resources we need
// _permId is the var that tells me the current id of this post
var posts = query;
postFull = [];
for(var i = 0; i < posts.length; i++) {
//terms.push(term);
var postObject = posts[i];
postFull.push(postObject);
for (var key in postObject) {
//console.log(postObject[key]);
if (postObject[key] === _permId) {
console.log('this is the same as this post');
}
}
};
},
cache: false
});
};
我想要做的不是通過允許任何內容,如果後期對象ID相同的值_permId
。
這裏是與鍵和值檢索的JSON的一個想法:
Object {ID: 4434, title: "new brand case", status: "publish", type: "case-studies", author: Object…}
ID是我想設置針對一個參數的值。
您的問題解決了嗎? – Sacreyoule