"use strict"; Component({ properties: { gridname: { type: String, value: "", }, }, data: { showText: "", }, observers: { gridname: function (val) { this.computeShowText(); }, }, lifetimes: { ready: function () { this.init(); }, }, methods: { init: function () { }, computeShowText: function () { var gridname = this.data.gridname; var arr = gridname.split('-'); var temp = ""; for (var i = 0; i < arr.length; i++) { if (i == (arr.length - 1)) { temp += this.substr(i, arr[i]); } else { temp = temp + this.substr(i, arr[i]) + "-"; } } this.setData({ showText: temp }); }, substr: function (index, str) { console.log(index, str); var temp = ""; if (index == 0) { if (str.length > 3) { temp = str.substring(0, 3) + '...'; } else { temp = str; } } else if (index == 1) { if (str.length > 5) { temp = str.substring(0, 3) + '...' + str.substring(str.length - 2); } else { temp = str; } } else if (index == 2) { if (str.length > 5) { temp = str.substring(0, 2) + '...' + str.substring(str.length - 3); } else { temp = str; } } return temp; } }, });