Reusing js code
I'm working on an Android app. I have a tableview that I want to resuse in different windows in my app. So i figured I could make a separate js file for this tableview. I have tried the following test in the app.js:
var winX = Titanium.UI.createWindow({
url : 'test.js'
});
var myview = Titanium.UI.createView({
height:300,
width:200,
borderColor:'red',
borderRadius : 10,
backgroundColor : 'red'
});
myview.add(winX);
win1.add(myview);
The test.js file only contains a button, for test. This doesn't work, how can I solve the problem?
6 Answers
-
I have a couple comments, not sure how much they will help but I'll give it a shot.
You usually need to call the open method of a window to make it display, I don't see that in this code so that may be why you see nothing. For example:
winX.open();
My next comment is that windows typically hold views, not the other way around so myview.add(winX); doesn't really make sense to me.
Hope this helped.
-
Also where is the TableView in your code?
-
Also where is the TableView in your code?
-
Also where is the TableView in your code?
-
Hi, and thanks for the input. The following situation is not exactly mine, but exactly similar to it:
Problem:
- I have four tableViews tv1, tv2, tv3, tv4
- I also have Two Tabs
- In Tab One I need TWO tableViews, tv1 and tv2
- In Tab Two I also need TWO tableViews, tv3 and tv4
My failing idea:
- Create TWO child windows in Each of the two root windows/tabs.
- For Each child window, use the URL property to connect to one of the JS files with a tableView in it.
Question:
What is a good way to organize/access tableViews/JS-files in this (I assume quite normal) situation?
Brgrds /JP
-
Guess this should Work…
app window(in which ever you want to reuse the table…. just include the js file and on the open event of window add it to a view in the window)
//include the test.js Ti.include('test.js'); //app window var win=Ti.UI.createWindow({}); //content View var Vu=Ti.UI.createView({}); win.add(Vu); win.open(); win.addEventListener('open',function(e){ Vu.add(TbVu); });
the test.js file
//test.js var TbVu=Ti.UI.createTableView({ data:data });