为了账号安全,请及时绑定邮箱和手机立即绑定

后台传入的json数据,前端jquery如何取出所有type=1的title啊?

后台传入的json数据,前端jquery如何取出所有type=1的title啊?

慕侠2389804 2019-03-15 22:19:12
[{"content":"1","create_time":"2018-02-27 15:31:54","id":"0a4faa259fdf4e46b7a8ee371651b0d1","state":0,"title":"1","type":1},{"content":"1","create_time":"2018-02-27 15:32:17","id":"1c8f1404256a407d984e109e8117e827","state":0,"title":"1","type":1},{"content":"1","create_time":"2018-02-27 17:39:08","id":"1de747cb35884682afecea7e2d2dc092","state":0,"title":"1","type":1},{"content":"1","create_time":"2018-02-27 15:32:52","id":"4b4f712d995d4c66b54925a20d8d1c63","state":0,"title":"1","type":1},{"content":"3","create_time":"2018-02-27 17:45:20","id":"59ceded6b3024b3b95bfb1b59619027e","state":0,"title":"3","type":1},{"content":"<p>??????</p><p>???</p><p>&nbsp; &nbsp;??</p>","create_time":"2018-02-27 17:46:04","id":"5ad093e29a404578aa1c3b1c1fe5e477","state":0,"title":"??????","type":2},{"content":"<p>???</p><p>???</p><p>&nbsp; &nbsp; &nbsp; &nbsp;??</p>","create_time":"2018-02-27 17:16:48","id":"6c95cfc93369474bb4f00085fe36e7d3","state":0,"title":"3","type":1},{"content":"3","create_time":"2018-02-27 17:44:24","id":"81871baf05fb44b38d0dd028d91cc2dd","state":0,"title":"3","type":1},{"content":"3","create_time":"2018-02-27 17:06:23","id":"98b15a3b69ea4d6db26ea76b86e6ce7a","state":0,"title":"3","type":1},{"content":"2","create_time":"2018-02-27 16:46:41","id":"fe2823ef07bd48acbeadf48a6e7ff85c","state":0,"title":"2","type":1}]
查看完整描述

5 回答

?
青春有我

TA贡献1784条经验 获得超8个赞

json.filter(function(item){

    return item.type===1;

}).map(function(item){

    return item.title

})


查看完整回答
反对 回复 2019-03-18
?
万千封印

TA贡献1891条经验 获得超3个赞

  var result = [] // 存储所有type为1的title


  for (var i = 0; i < list.length; i++) {

    var item = list[i]


    if (item.type === 1) {

      result.push(item.title)

    }

  }


查看完整回答
反对 回复 2019-03-18
?
江户川乱折腾

TA贡献1851条经验 获得超5个赞

看了前面大神们的回答,所用到的方法大体差不多,这里我就推荐一个插件吧 linq.js 
然后过滤的代码你就可以这样去写:

Enumerable.From(json).Where("$.type === 1").Select("$.title").ToArray();

推荐文章:玩转 linq.js


查看完整回答
反对 回复 2019-03-18
  • 5 回答
  • 0 关注
  • 733 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信