3

我有一个绑定到数据源的剑道列表视图。当用户单击我调用的添加按钮时$("#arealistview").data("kendoMobileListView").prepend([newItem]),它将一个新项目添加到列表的开头。

如何获取列表视图中项目的计数?

4

3 回答 3

6

数据源的方法应返回:

var total = $("#arealistview").data("kendoMobileListView").dataSource.total();

或者可以获取data方法返回的数组长度:

var data = $("#arealistview").data("kendoMobileListView").dataSource.data();
var total = data.length;
于 2013-08-17T07:16:00.303 回答
0

我相信你应该能够做到

var numItems=$("#arealistview").data("kendoMobileListView").length;

您可以随时参考这里http ://docs.kendoui.c​​om/api/web/listview 如果这仍然没有产生任何结果,我建议与 Kendo 代表联系,他们是非常乐于助人的人。

于 2013-08-16T20:29:05.413 回答
0

<!DOCTYPE html>
<html>
<head>
    <base href="https://demos.telerik.com/kendo-ui/treeview/dragdrop">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.1.115/styles/kendo.common-material.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.1.115/styles/kendo.material.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.1.115/styles/kendo.material.mobile.min.css" />

    <script src="https://kendo.cdn.telerik.com/2019.1.115/js/jquery.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2019.1.115/js/kendo.all.min.js"></script>
    

</head>
<body>
        <div id="example">
            <div class="demo-section k-content">
                <h4>Treeview One</h4>
                <div id="treeview-left"></div>
            </div>
          
      <script id="treeview-template" type="text/kendo-ui-template">
            #= item.text # <span class='item-count'></span>
        </script>
  
            <script>
                $("#treeview-left").kendoTreeView({
                   template: kendo.template($("#treeview-template").html()),
                  
                    dataSource: [
                        { text: "Furniture", expanded: true, items: [
                            { text: "Tables & Chairs" },
                            { text: "Sofas" },
                            { text: "Occasional Furniture" }
                        ] },
                        { text: "Decor", items: [
                            { text: "Bed Linen" },
                            { text: "Curtains & Blinds" },
                            { text: "Carpets" }
                        ] }
                    ],
                   dataBound: function(e) {
                     
                var item = this.dataItem(e.node);
                var children = item && item.children ? item.children.data().length : undefined; 
                var text = children ? ("(" + children + ")") : "";
                $(e.node).find(">div .item-count").text(text);
              }
                });

                $("#treeview-right").kendoTreeView({
                    dragAndDrop: true,
                    dataSource: [
                        { text: "Storage", expanded: true, items: [
                            { text: "Wall Shelving" },
                            { text: "Floor Shelving" },
                            { text: "Kids Storage" }
                        ]
                        },
                        { text: "Lights", items: [
                            { text: "Ceiling" },
                            { text: "Table" },
                            { text: "Floor" }
                        ]
                        }
                    ]
                });
            </script>

            <style>
                #treeview-left,
                #treeview-right
                {
                    overflow: visible;
                }
            </style>
        </div>


</body>
</html>

这是用于树视图

于 2019-02-11T11:13:06.693 回答