开发者

jquery json can each be used to do something like each where title='mytitle'

开发者 https://www.devze.com 2023-03-01 14:46 出处:网络
$.each(udt.Data, function(i, Data) { $(\"#output\").append(\"<h4>\" + Data.productTitl开发者_如何学编程e + \"</h4>\");
            $.each(udt.Data, function(i, Data) {
                $("#output").append("<h4>" + Data.productTitl开发者_如何学编程e + "</h4>");
            });

I have the above code to loop through a json result what would be the best way to do something like for each Data where productTitle = 'product1'


You can try $.grep()

var arr = $.grep(udt.Data, function(Data, i){
  return Data.productTitle === 'product1';
});

Example on jsfiddle

0

精彩评论

暂无评论...
验证码 换一张
取 消