有什么办法可以动态地将数据添加到网格中吗?

时间:2018-10-09 11:51:15

标签: bbc-tal

我有一个带有n个小部件的轮播,并且一旦用户将焦点移到该轮播的最后一项,我想再向该轮播加载n个项目。我在轮播中添加了afteralign事件侦听器,以检测轮播项之间的导航,并且在侦听器内部我创建了一个小部件,并尝试使用appendChildWidget()方法将其附加到当前的轮播中

 _handleLazyLoading: function (evt) {
                var selectedItem = evt.target.getActiveChildWidget().getDataItem();
                if (selectedItem.page < selectedItem.totalPages) {
                    if (evt.target.getActiveChildIndex() === evt.target.getChildWidgetCount() - 3) {
                        var sampleData={"type":"VOD","id":1234,"accessLevel":"GRANTED","title":"sample","description":"A look back at all the Premier League action from the 31st of March 2018.","thumbnailUrl":"url of image","metaFields":{},"tags":
                        ["review","match-round-32"],"watchProgress":0,"favourite":true,"duration":3098,"watchedAt":1522675749000}
                        var videoCard=new CommonVideoCard(sampleData);
                        evt.target.appendChildWidget(sampleData)
                    }
                }
            }

这是我的事件侦听器代码。我还检查了dom,如果我在追加方法之后放置了一个断点,则之后我可以看到dom中的数据,这似乎是特定的轮播卡住了,并且我无法导航到该轮播中的其他项目。 我只是尝试使用removeWidget方法,它可以工作。 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

在附加新的子窗口小部件后设置setWidgetLengths(length);

所以代码看起来像

 _handleLazyLoading: function (evt) {
                var selectedItem = evt.target.getActiveChildWidget().getDataItem();
                if (selectedItem.page < selectedItem.totalPages) {
                    if (evt.target.getActiveChildIndex() === evt.target.getChildWidgetCount() - 3) {
                        var sampleData={"type":"VOD","id":1234,"accessLevel":"GRANTED","title":"sample","description":"A look back at all the Premier League action from the 31st of March 2018.","thumbnailUrl":"url of image","metaFields":{},"tags":
                        ["review","match-round-32"],"watchProgress":0,"favourite":true,"duration":3098,"watchedAt":1522675749000}
                        var videoCard=new CommonVideoCard(sampleData);
                        evt.target.appendChildWidget(sampleData);
                        evt.target.setWidgetLengths(620);
                    }
                }
            }