返回值After Filter方法未正确过滤

时间:2017-06-05 23:25:56

标签: javascript jquery ajax api

尝试过滤掉等于' self'的缩略图值。或默认,但它仍然无法正常工作,除了过滤器还有其他方法吗?

 $(document).ready(function(){
   $('button').on('click', function(event){
    event.preventDefault();
    $('#result').empty();
    var userInput = $('input').val()
        $.ajax({
        method:"GET",
        url:"https://www.reddit.com/r/" + userInput + ".json?jsonp",
        success:success
    })
    })

function success(response){
    var result ="";
    $.each(response, function(index, value){
        var list = response.data.children
        $.each(list.filter(function(item){
            return item.data.thumbnail !== "self" || "default"
        }), 
            function(index,value){
                var thumbnail = value.data.thumbnail
                var author = value.data.author
                result += "<li>" + 
                            "<img src='" + thumbnail + "' class='reddit-image'/>"

                result += "<p class='reddit-author'>" + author + "</p>"
                result += "</li>"
                $('#result').html(result)
            })
        })
    }
})

1 个答案:

答案 0 :(得分:0)

您的退货声明表示如果值不是'self',则返回字符串 'default'

字符串'default'是真实的

您需要将变量与两个字符串进行比较

 return item.data.thumbnail !== "self" || item.data.thumbnail !== "default"