简体   繁体   English

如何在Blackberry 10本机中获取ListView位置

[英]How to get listview position in Blackberry 10 native

I am trying to load data from web-services into list-view and i am successfully able to load that particular data into my list-view. 我正在尝试将Web服务中的数据加载到列表视图中,并且我能够成功地将特定数据加载到我的列表视图中。

But the problem i am facing is i am getting 10 data per page in list-view and when user scroll down it tries to load more data and when it loads more data into list-view, list-view start showing data from 1st data itself, instead of 1st data i want to show current data. 但是我面临的问题是我在列表视图中每页获取10个数据,并且当用户向下滚动时,它尝试加载更多数据,并且在将更多数据加载到列表视图中时,列表视图开始显示第1个数据本身的数据,而不是第一数据,我想显示当前数据。

Ex. 防爆。 When user scrolls for more data that is page - 2 it will load another 10 data and now list-view contains 20 data, so currently user is at 10th position and loading more data so list-view should show from 11th data but instead of that it again start from 1st data itself, also when user loads 30 data then it should start showing data from 21 data but again it starting from 1st position. 当用户滚动查看更多数据时,即页面-2将加载另外10个数据,现在列表视图包含20个数据,因此当前用户位于第10位,正在加载更多数据,因此列表视图应从第11个数据开始显示,而不是显示它再次从第1个数据本身开始,同样,当用户加载30个数据时,它应该从21个数据开始显示数据,但从第1个位置开始。

So basically my question is how can i know the position of list-item and directly moves user to that particular position so directly user can see the current data. 所以基本上我的问题是我如何才能知道列表项的位置并将用户直接移动到该特定位置,以便用户可以直接看到当前数据。

The code i am trying is. 我正在尝试的代码是。

onScrollingChanged: {
              if (atEnd && scrolling == false
                   if (_app.powerDivert == 1) {
                          _app.powerDivert += 1;
                    }
                    if (connInfo.isConnected()) {
                              getPagewisePromotionList(_app.powerDivert);
                    }
                 }
             }

where powerDivert will increment the page-count and getPagewisePromotionList this is the function i am calling to add more data into the list-view. 其中powerDivert将增加页面计数和getPagewisePromotionList,这是我正在调用的功能,以将更多数据添加到列表视图中。

i have also tried. 我也尝试过。

  onFirstVisibleItemChanged: {
            if (position < firstVisibleItem) {
             console.log("Scrolling Down")
             var size = _app.dataModel.size();
             var percent = firstVisibleItem / size * 100;
             console.log("Percent: " + percent);
                  if (percent > 60) {
                            if (_app.powerDivert == 1) {
                            _app.powerDivert += 1;
                           }
                           if (connInfo.isConnected()) {
                               console.log("inside percentage");
                               getPagewisePromotionList(_app.powerDivert);
                           }
                       }
                      } else if (position > firstVisibleItem) {
                       console.log("Scrolling Up");
                    }
                   position = parseInt(firstVisibleItem);
                }

and also with this code 还有这个代码

onScrollingChanged: {
        if (ListItem.indexInSection + 5 == ListItem.indexPath) {
               if (_app.powerDivert == 1) {
                      _app.powerDivert += 1;
                }
               if (connInfo.isConnected()) {
                       getPagewisePromotionList(_app.powerDivert);
              }
         }
}

but it's giving me error like 但这给了我错误

Error: Accessing ListItem.indexInSection on a node that is not the root node in a list item visual. Try prefixing with the id of the item visual root node.
Error: Accessing ListItem.indexPath on a node that is not the root node in a list item visual. Try prefixing with the id of the item visual root node.

Please let me know if you need anything else. 如果您还有其他需要,请告诉我。

Thank you in advance. 先感谢您。

That Depends on you.How you are loading the data from services.If you are getting the data page wise then you can use this: 这取决于你自己。如何从服务中加载数据。如果要明智地获取数据页,则可以使用以下方法:

var indexPosition = (_app.powerDivert - 1) * 10;
lstPromotionListOnline.scrollToItem([ indexPosition ], ScrollAnimation.None);

Where powerdivert is your page_number and lstPromotionListOnline is your listview id 其中powerdivert是您的page_number, lstPromotionListOnline是您的listview ID

check this link for reference. 检查此链接以供参考。

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

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