0

ここであなたの助けが必要です。コンテンツを表示しようとするたびに、数回 (通常は 4 回) 表示されますが、1 回だけ表示する必要があります。私のコードの何が問題なのかわかりません。以下はどれですか:

$.ajax({
    url: 'https://' + subParam + '.domain.name/' + akey + '/get_article',
    async: false,
    callback: 'callback',
    crossDomain: true,
    contentType: 'application/json; charset=utf-8',
    type: 'POST',
    dataType: 'jsonp',
    success: function (data, status) {
        if (data !== undefined && data.post !== undefined) {
            if (data !== undefined && data.post.author.description > 0) {
                if (data.post.thumbnail_images.large.url !== undefined) {
                    $.each(data.post.thumbnail_images, function (i2, type) {
                        $('#news').append('<div id="nimg" style="background-image: url(' + data.post.thumbnail_images.large.url + ')"></div><a href="author.html?type=authors&id=' + data.post.author.description + '"><div id="circletag" style="background-image: url(' + data.post.author.nickname + ')"></div></a><div id="newstext"><div id="newstitle">' + data.post.title + '</div><div>' + data.post.content + '</div><div><a href="#" onclick="window.open(\'' + data.post.custom_fields.syndication_permalink + '#comments\', \'_system\', \'location=yes\');" id="verstovcomments"></a></div></div>');
                    });
                } else {
                    $('#news').append('<div id="nimg" style="background-image: url(' + defaultNews + ')"></div><a href="author.html?type=authors&id=' + data.post.author.description + '"><div id="circletag" style="background-image: url(' + data.post.author.nickname + ')"></div></a><div id="newstext"><div id="newstitle">' + data.post.title + '</div><div>' + data.post.content + '</div><div><a href="#" onclick="window.open(\'' + data.post.custom_fields.syndication_permalink + '#comments\', \'_system\', \'location=yes\');" id="verstovcomments"></a></div></div>');
                }
            }
        }
    }
});

....

私のjson応答は次のようになります。

{
    "status": "ok",
    "post": {
        "id": 3211,
        "title": "title",
        "content": "content"
        "thumbnail": "/uploads\/2013\/09\/matkapital-150x150.jpg",
        "thumbnail_size": "thumbnail",
        "thumbnail_images": {
           "full": {
                "url": "/uploads\/2013\/09\/matkapital.jpg",
                "width": 640,
                "height": 427
            },
            "thumbnail": {
                "url": "/uploads\/2013\/09\/matkapital-150x150.jpg",
                "width": 150,
                "height": 150
            },
            "medium": {
                "url": "/uploads\/2013\/09\/matkapital-250x166.jpg",
                "width": 250,
                "height": 166
            },
            "large": {
                "url": "/uploads\/2013\/09\/matkapital-640x426.jpg",
                "width": 640,
                "height": 426
            }
        }
    }
}

私が使用しているからです$.eachか、それとも他の問題がありますか?

4

3 に答える 3

0

$.each(data.post.thumbnail_images, function (i2, type) で、thumbnail_images を custom_fields に変更したところ、結果の乗算が停止しました。

 $.ajax({
url: 'https://' + subParam + '.domain.name/' + akey + '/get_article',
async: false,
callback: 'callback',
crossDomain: true,
contentType: 'application/json; charset=utf-8',
type: 'POST',
dataType: 'jsonp',
success: function (data, status) {
    if (data !== undefined && data.post !== undefined) {
        if (data !== undefined && data.post.author.description > 0) {
            if (data.post.thumbnail_images.large.url !== undefined) {
                $.each(data.post.custom_fields, function (i2, type) {
                    $('#news').append('<div id="nimg" style="background-image: url(' + data.post.thumbnail_images.large.url + ')"></div><a href="author.html?type=authors&id=' + data.post.author.description + '"><div id="circletag" style="background-image: url(' + data.post.author.nickname + ')"></div></a><div id="newstext"><div id="newstitle">' + data.post.title + '</div><div>' + data.post.content + '</div><div><a href="#" onclick="window.open(\'' + data.post.custom_fields.syndication_permalink + '#comments\', \'_system\', \'location=yes\');" id="verstovcomments"></a></div></div>');
                });
            } else {
                $('#news').append('<div id="nimg" style="background-image: url(' + defaultNews + ')"></div><a href="author.html?type=authors&id=' + data.post.author.description + '"><div id="circletag" style="background-image: url(' + data.post.author.nickname + ')"></div></a><div id="newstext"><div id="newstitle">' + data.post.title + '</div><div>' + data.post.content + '</div><div><a href="#" onclick="window.open(\'' + data.post.custom_fields.syndication_permalink + '#comments\', \'_system\', \'location=yes\');" id="verstovcomments"></a></div></div>');
            }
        }
    }
}

});

于 2013-09-20T10:11:35.797 に答える