PDA

View Full Version : find dynamic view without using searchSubviews


yuna
06-08-2007, 11:19 AM
HI there,

<canvas>
<view id="FirstView">
<view id="First_1"/>
<view id="First_2"/>
<view id="First_3"/>
....
</view>

<view id="SecondView">
....
</view>

<view id="ThirdView">
....
</view>

<view id="FourthView">
<view id="Fourth_1"/>
<view id="Fourth_2"/>
<view id="Fourth_3">
// execute functions and display subviews of fourth_3 view
</view>
....
</view>

<view id="FifthView">
....
</view>
.....

</canvas>

var f = "Fourth"
var s = "3"
var seachView_name = f+"_"+s;
var mySearchView = canvas.searchSubviews("id", seachView_name);


"f" and "s" variables are unknown until user input them, and need to find the view and display after user select them.
In this case, it seems like searchSubviews will be good option,
however, the application is pretty big and searching subview from the canvas could be related with speed issue.

I know the name of view I am going to search (e,g, "Fourth_3" view in this case")

Is there any way I can convert the string to view object without using searchSubviews so that I can just use (searchView_name).somefunction() ?

Thank you!

senshi
06-08-2007, 01:12 PM
Is there any way I can convert the string to view object without using searchSubviews so that I can just use (searchView_name).somefunction() ?

If you're working with id's, there is actually no need to take "searchSubviews(..)" at all.
You can use either eval(..) or global for this purpose:


<canvas debug="true" >

<view>
<view>
<view>
<view>
<view>
<!-- this view is pretty much wrapped -->
<view id="foo" >
<method name="test" args="s" >
Debug.write( s );
</method>
</view>
</view>
</view>
</view>
</view>
</view>

<script>
var sFoo = "foo";
eval( sFoo ).test( "Hello World!" );
global[sFoo].test( "Hello World!" );
</script>

</canvas>

yuna
06-08-2007, 01:53 PM
Thanks senshi, That helps a lot!

what if I also need to call dynamic method under the view,
is there any way to execute beside using Delegate?

example code using delegate:

var view_name= "View"+f;
var viewID = global[view_name];

var method_name = "run" + some name related user input;

var myDelegate = new LzDelegate(viewID, method_name);
var result = myDelegate.execute();

senshi
06-08-2007, 02:07 PM
In this case, you can use the bracket-notation, too.


<canvas debug="true" >

<view>
<view>
<view>
<view>
<view>
<view id="foo" >
<method name="test" args="s" >
Debug.write( s );
</method>
</view>
</view>
</view>
</view>
</view>
</view>

<script>
var sFoo = "foo";
var sFunc = "test"
global[sFoo][sFunc]( "Hello World!" );
</script>

</canvas>

yuna
06-08-2007, 02:15 PM
Got it!
Thanks Senshi.

Yuna