我重复了一堆要应用省略号的文本。我正在使用 jquery dotdotdot。 dotdotdot 文档
我做了一个简单的指令,看起来像
angular.module('core').directive('dotdotdot', [function () {
return {
required: 'ngBind',
restrict: 'A',
replace: false,
priority: 100,
link: function ($scope, element, attrs, ctrl) {
$scope.isTruncated = false;
$scope.hasRun = false;
$scope.$watch(element.html(), function (value) {
if (!$scope.hasRun) {
$scope.hasRun = true;
element.dotdotdot({watch:'window',
after: 'a.dotdotdotMore'});
$scope.isTruncated = element.triggerHandler('isTruncated');
if ($scope.isTruncated){
console.log('Truncated');
} else {
console.log('NOT Truncated');
}
}
});
}
};
}]);
应用省略号可以正常工作,但是当有人单击我希望它展开的项目时。
我的 html 看起来像
<div class="review item" data-ng-repeat="review in creator.reviews | orderBy:'order' track by $index">
<h1 dotdotdot data-ng-bind="review.review" class="testimonial" data-ng-class="{'testimonial-truncate': showTestimonial !== $index}" data-ng-click="testimonialClick($index);"></h1>
</div>
testimonial-truncate 的 css 是
.testimonial-truncate {
max-height:200px;
}
我的点击功能看起来像
$scope.testimonialClick = function (index) {
if ($scope.showTestimonial && $scope.showTestimonial === index) {
$scope.showTestimonial = -1;
} else {
$scope.showTestimonial = index;
}
$timeout(function() {
$('.testimonial').trigger('update');
}, 200);
};
似乎代码都被调用了,但即使删除了该类,文本仍被截断到最大高度。
我正在寻找一个解决方案,所以要么我如何获得我所做的工作,要么有更好的方法来做到这一点。