1.控制文本长度,超出省略号
在模版中:
<label>{{item.abbr| cut:true:20:‘ ...‘ }}<label>
js:
angular.module(‘app‘).filter(‘textLengthSet‘, function() {
return function(value, wordwise, max, tail) {
if (!value) return ‘‘;
max = parseInt(max, 10);
if (!max) return value;
if (value.length <= max) return value;
value = value.substr(0, max);
if (wordwise) {
var lastspace = value.lastIndexOf(‘ ‘);
if (lastspace != -1) {
value = value.substr(0, lastspace);
}
}
return value + (tail || ‘ …‘);//‘...‘可以换成其它文字
};
});
时间: 2024-10-06 09:59:46