1 angular.module(‘ng‘).filter(‘cut‘, function () { 2 return function (value, wordwise, max, tail) { 3 if (!value) return ‘‘; 4 5 max = parseInt(max, 10); 6 if (!max) return value; 7 if (value.length <= max) return value; 8 9 value = value.substr(0, max); 10 if (wordwise) { 11 var lastspace = value.lastIndexOf(‘ ‘); 12 if (lastspace != -1) { 13 value = value.substr(0, lastspace); 14 } 15 } 16 17 return value + (tail || ‘ …‘); 18 }; 19 });
使用方式:{{some_text | cut:true:100:‘ ...‘}}
时间: 2024-09-30 15:36:50