0
votes

I have a scrollableView with several views inside and I'd like to add item to some of these view if they meet a certain criteria, like if they have data attached or not. Also I'm using Alloy, here's my markup

<ScrollableView id="scrollableView">
    <View id="view" class='coolView'></View>
    ...
</ScrollableView>

To know if there are data attached I check the currentPage attribute like so:

function updateCurrentView(e) {
    currentView = e.currentPage;
}

But I have no idea how to add an item to the current View.

Edit: To add some clarification, I have a label which when clicked allow me to choose two currencies, when chosen these currency pairs are saved in the database and should be displayed instead of the label. So my guess was to check whether the current view has currency pair saved.

1
Hi Jonathan Can you please elaborate? What items are you adding?What kind of data attached?Mukund Samant
@MukundSamant, I have add the details :)Jonathan de M.

1 Answers

3
votes

There are 2 things to take care of here:

1.Whenever a currency is selected,immediately label on that particular view will change.

2.Whenever the scrollableView is loaded,it must always refer to the database if a currency is selected.

First one can be done as:

1.Get the instance of scrollableView using the getView method of alloy controller.Pass the id of the scrollableView to it.Lets call it myScrollableView.Refer this for more info.

http://docs.appcelerator.com/titanium/latest/#!/api/Alloy.Controller

2.Use var currentView=myScrollableView.getCurrentPage() to the get the current page which will be a number.

3.Now use the scrollableView instance to get all the views.

var viewArray=myScrollableView.getViews();

4.viewArray[currentView] will give you the view of current page.After you have got the view you can change the desired label using:

 viewArray[currentView].children[positionOfTheView]

The "positionOfTheView" can be obtained by printing the viewArray[i].children array using Ti.API.info.

Second thing can be accomplished as follows:

1.Get the instance of scrollableView using the getView method of alloy controller.Pass the id of the scrollableView to it.Lets call it myScrollableView.Refer this for more info.

http://docs.appcelerator.com/titanium/latest/#!/api/Alloy.Controller

2.Now use the scrollableView instance to get all the views.

var viewArray=myScrollableView.getViews();

3.This is a JavaScript array of all the views in the scrollableView. Now iterate through this array and according to the data in the database,change the concerned view using:

viewArray[i].children[positionOfTheView]

The "positionOfTheView" can be obtained by printing the viewArray[i].children array using Ti.API.info.