小程序 数据处理 摘取有用数据
![](https://images2018.cnblogs.com/blog/1117150/201711/1117150-20171129141107612-1506520871.png)
processDoubanData: function (moviesDouban) { var movies = [];//定义一个数组,在数据绑定时wx:for 可使用数组中各项的数据重复渲染该组件,其实就是把摘取了有用的数据存放在了movies for (var idx in moviesDouban.subjects) {//for...in 语句循环遍历数组 var subject = moviesDouban.subjects[idx];//获取数组里的每一个对象 var title = subject.title; if (title.length >= 6) { title = title.substring(0, 6) + "..."; } // [1,1,1,1,1] [1,1,1,0,0] var temp = { stars: util.convertToStarsArray(subject.rating.stars), title: title, average: subject.rating.average, coverageUrl: subject.images.large, movieId: subject.id } movies.push(temp) }this.setData({movies:movies}); }
var movies = []; var temp = { stars: 1, title: 2, average: 3, coverageUrl: 4, movieId:5 } movies.push(temp); console.log(movies);
//[{stars: 1, title: 2, average: 3, coverageUrl: 4, movieId: 5}]