//计算汉字长度 function DataLength(fData) { var reg = /[\u4e00-\u9fa5]/g; return fData.match(reg).length; } 用到地方标题样式
slideNav: [ { "title": "电子名片","type":"4","icon":"../../images/3.png"}, {"title": "维修技师","type":"5","icon":"../../images/1.png"}, {"title":"服务顾问","type":"2","icon":"../../images/3.png"}, {"title":"销售顾问","type":"3","icon":"../../images/1.png"}, {"title":"车险顾问","type":"1","icon":"../../images/3.png"}, { "title": "报价单","type":"2","icon":"../../images/1.png"}, { "title": "二手车评估师","type":"3","icon":"../../images/1.png"}, { "title": "车险顾问","type":"1","icon":"../../images/3.png"} ]
var s_nav = slideNav; for (let nav_index in s_nav) { var nav_length = ataLength(s_nav[nav_index]["title"]); var length_class = (nav_length == 2 || nav_length == 4) ? 'duble_row' : 'third_row'; slideNav[nav_index]['length'] = length_class; } this.setData({ "slideNav": this.data.slideNav });