Nativescript Code Behind - Add GridLayout to ScrollView Dynamically

北城以北 提交于 2020-01-06 05:17:47

问题


I am creating a dynamic GridLayout in Nativescript following the example on there page:

https://docs.nativescript.org/ui/layouts/layout-containers

It allows my to make a GridLayout using javascript, as I need it to be dynamic.

However, I want to put this layout in a ScrollView.

I believe I'm meant to do something like this

const grid = new GridLayout();
const scroll = new ScrollView();  
grid.addChild();

...

scroll.addView(grid);

I constantly get an error saying "addView" is not a function.

Is this the correct method? What 'require("");' do I need for the ScrollView?

Thanks


回答1:


You need to import from import { ScrollView } from 'ui/scroll-view';

and it's not addView, available public method is _addView




回答2:


So just as reference for anyone else in the future.

The _addView() method wouldn't throw any errors, however I couldn't get the scene to actually load or show anything.

If there is a way to load the _addView() correctly then more than happy fo someone to add that comment.

The playground for that method is below:

https://play.nativescript.org/?template=play-js&id=LlsHLd

The way I got it working is by doing the following:

const scrollView = require("tns-core-modules/ui/scroll-view").Scroll-View;
var scrollV = new scrollView();

(Dynamically load a gridlayout)
grid.addChild()
....

scroll.content = grid;
page.content = scroll;

Thanks everyone for the help.



来源:https://stackoverflow.com/questions/52825771/nativescript-code-behind-add-gridlayout-to-scrollview-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!