简体   繁体   English

ListView没有滚动条

[英]ListView doesn't have scrollbar

I have problem with scrollbar 我的滚动条有问题

Inside body I have div like this: 在体内,我有这样的股利:

<div id="PageBody"></div>

There I load my listview with javascript 在那里,我用javascript加载了listview

WinJS.UI.Pages.render("./pagebody.html",document.getElementById("PageBody"), null, true);

PageBody.html looks like this PageBody.html看起来像这样

<!-- Simple template-->
<div class="smallListIconTextTemplate" data-win-control="WinJS.Binding.Template" style="display: none">
    <div class="smallListIconTextItem">
        <img src="#" class="smallListIconTextItem-Image" data-win-bind="src: picture" />
        <div class="smallListIconTextItem-Detail">
            <h4 class="win-h4" data-win-bind="textContent: title"></h4>
            <h6 class="win-h6" data-win-bind="textContent: text"></h6>
        </div>
    </div>
</div>

<!-- listview-->
<div id="listView"
     class="win-selectionstylefilled"
     data-win-control="WinJS.UI.ListView"
     data-win-options="{
            itemDataSource: Sample.ListView.data.dataSource,
            itemTemplate: select('.smallListIconTextTemplate'),
            selectionMode: 'none',
            tapBehavior: 'none',
            layout: { type: WinJS.UI.ListLayout }
    }">
</div>

Now, if my listview contains bigger number of items (all items cannot be displayed at once), then the scrollbar doesn't appear, and I can't access hidden elements. 现在,如果我的列表视图包含更多项(无法一次显示所有项),则不会出现滚动条,并且我无法访问隐藏的元素。

If I make the listview normally (without loading it into div) scrolling works normally. 如果我使列表视图正常(不将其加载到div中),则滚动正常。 However, I need to load different listviews or other controls into that div (depending on what data user wants) 但是,我需要将不同的列表视图或其他控件加载到该div中(取决于用户所需的数据)

How can I get around this problem? 我该如何解决这个问题?

UPDATE: I added to "PageBody" div this: style="overflow: scroll" scrollbar shows, but doesn't work (u can't scroll) 更新:我在“ PageBody” div中添加了以下内容:style =“ overflow:scroll”滚动条显示,但是不起作用(u无法滚动)

UPDATE2: With grid layout scrolling works, but still with list layout doesn't UPDATE2:可以使用网格布局滚动,但是仍然不能使用列表布局

Put this CSS into your div in which data is populating: 将此CSS放入要填充数据的div中:

  overflow-y:auto;

JSFiddle for it. JSFiddle为此。

The problem was 问题是

height: 100%

in .css file 在.css文件中

I removed it, but then the only problem was how to fit listview to the page. 我删除了它,但是然后唯一的问题是如何将listview适应页面。 I dealt with it within javascript. 我在javascript中处理过。

window.addEventListener("resize", function () {
            var listviewdiv = document.getElementById("listView");
            var h = window.innerHeight;

            listviewdiv.setAttribute("style", "height:" + h.toString() + "px");
        });

And then the only problem remains is how to do it initially, when application is created and loaded (code above works only after user resizes window) 然后剩下的唯一问题是创建和加载应用程序时的初始操作(上面的代码仅在用户调整窗口大小之后有效)

For that case I've put this code: 对于这种情况,我将以下代码放入:

WinJS.UI.Pages.render("./PageBody.html", PageBody).done(function () {
            var listviewdiv = document.getElementById("listView");
            var h = window.innerHeight;

            listviewdiv.setAttribute("style", "height:" + h.toString() + "px");
        });

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

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