我是 angularJS 的新手,也许写了一些不好的东西......
但我怎样才能正确实现这个插件:https://github.com/BeSite/jQuery.dotdotdot
在我的桌子上吗?
现在用我的代码我的编辑表单和表格真的不太快...真的太慢...我做错了什么?
指示:
.directive('dotdotdot', function(){
return {
restrict: 'A',
link: function(scope, element, attributes) {
scope.$watch(function() {
element.dotdotdot({watch: true, wrap: 'letter'});
});
}
}
});
和表:
<table id="articles" class="table table-striped articles-table">
<thead>
<tr class="table-row">
<th data-ng-click="predicate = 'Date'; reverse=!reverse">Date<i ng-class="{'arrow-down' : (reverse && predicate==='Date') || (predicate!=='Date'), 'arrow-up' : !reverse && predicate==='Date'}"></i></th>
<th data-ng-click="predicate = 'Title'; reverse=!reverse">Title<i ng-class="{'arrow-down' : (reverse && predicate==='Title') || (predicate!=='Title'), 'arrow-up' : !reverse && predicate==='Title'}"></i></th>
<th data-sorter="false">article</th>
<th data-sorter="false"></th>
<th data-sorter="false"></th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="article in articles | orderBy:predicate:reverse" data-id="{{article.Id}}" class="table-row">
<td class="text-nowrap">
<div class="articles-cell">
{{article.Date}}
</div>
</td>
<td>
<div class="articles-cell article-text-area" dotdotdot>
{{article.Title}}
</div>
</td>
<td>
<div class="articles-cell">
<a href="javascript:void(0)" data-ng-click="showarticle(article)" data-toggle="modal" data-target="#new-article" class="action">
<img data-ng-src="{{article.Photo}}" data-err-src="images/no_photo.png" class="article-img img-rounded img-responsive" alt="article" />
</a>
</div>
</td>
<td>
<div class="articles-cell" dotdotdot>
<div class="content" data-ng-bind-html="article.Content" class="articles-row" ></div>
</div>
</td>
<td class="crud-arr">
</td>
</tr>
</tbody>
</table>
即使我通过绑定重写它 - 它也很慢......
我做错了什么?
正如 @pankajparkar 在评论中指出的那样,这确实不应该在$watch
。这样做会执行element.dotdotdot()
在任何给定会话中都会多次调用配置 - 例如每次按下按键或单击鼠标时。速度减慢的部分原因可能是插件本身及其管理观看的方式,但除此之外,您应该通过简单地删除 $watch 来看到改进:
.directive('dotdotdot', function(){
return {
restrict: 'A',
link: function(scope, element, attributes) {
element.dotdotdot({watch: true, wrap: 'letter'});
}
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)