我有一堆文本重複我想應用省略號。我正在使用jquery dotdotdot。 dotdotdot documentationdotdotdot看到更多不能與Angularjs合作
我做了一個簡單的指令,看起來像
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>
的告別賽,截斷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);
};
好像代碼都被稱爲但即使刪除了該類,文本仍會截斷到最大高度。
我正在尋找解決方案,所以要麼我如何得到我所做的工作,要麼有更好的方法來做到這一點。
爲什麼要投票?我可以改變這個問題嗎?我該如何改進它? – Leo
只是可以肯定的是,你有一堆與擴展按鈕塊。點擊時你想讓它顯示所有的文字,對吧? –
那麼'dotdotdot'是做什麼的?沒有代碼顯示該指令 – charlietfl