简体   繁体   English

如何在 Angular 2 Kendo UI Sortable 中隐藏“Empty”结果?

[英]How do I hide "Empty" results in Angular 2 Kendo UI Sortable?

I am using Angular 2 Kendo UI Sortable in my app to display some dynamically-generated lists of values.我在我的应用程序中使用Angular 2 Kendo UI Sortable来显示一些动态生成的值列表。 Sometimes, the list is empty.有时,列表是空的。 Kendo insists on displaying a big ugly "Empty", and I can't understand how to get rid of it.剑道执意要施展一个大丑“空”,我不明白怎么摆脱。

                     <kendo-sortable [navigatable]="true" [data]="newTree | treeBuilder:item.id">
                      <ul>
                        <ng-template *ngIf="item" let-item="item"> // Nope this doesn't work.
                          <li>
                            <div class="child-2">{{item}}</div>
                          </li>
                        </ng-template>
                      </ul>
                    </kendo-sortable>

OK, it is actually mentioned in the docs .好的,它实际上在docs 中提到。 There are 3 relevant attributes:有3个相关属性:

emptyItemClass空项目类

Defines the class which is applied to the empty item when the Sortable has empty data.定义当 Sortable 有空数据时应用于空项目的类。

emptyItemStyle空项目样式

Defines the CSS styles applied to an empty item.定义应用于空项目的 CSS 样式。

emptyText空文本

Sets the text message that will be displayed when the Sortable has no items.设置当 Sortable 没有项目时将显示的文本消息。

Setting the empty text to "" simply makes it default to "Empty" again.将空文本设置为 "" 只会使其再次默认为 "Empty"。 So the solution I found is to use the emptyItemStyle attribute and specify display:none , and that's finally got rid of it.所以我找到的解决方案是使用emptyItemStyle属性并指定display:none ,最后摆脱了它。 Phew.呼。

Stupid feature.愚蠢的特征。 Why not just leave it up to users to specify their own custom content if they need it using template conditionals?...如果用户需要使用模板条件,为什么不让用户指定他们自己的自定义内容呢?...

假设item是一个Array ,请尝试*ngIf="item.length > 0"

You can use like this:你可以这样使用:

...
<kendo-sortable [navigatable]="true" [data]="newTree | treeBuilder:item.id" [emptyText]="''">
</kendo-sortable>
...

with

[emptyText]="''" [空文本]="''"

you can custom your message for empty result or put it empty like me, it will not show empty again.您可以为空结果自定义消息,也可以像我一样将其设为空,它不会再次显示为空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM