问题描述:

I'm studing Codestrong 2012 app and trying to make it work on SDK 3.1.3.

I thought xml views should have unique id's, but I've found this:

//main.xml

<Alloy>

<View id="container">

<View id="content"> </View>

<!-- ... -->

</View>

</Alloy>

and

//drawer.xml

<Alloy>

<View id="container">

<!-- ... -->

</View>

</Alloy>

then, mains.js controller have a piece of code that does:

var d = Alloy.createController('drawer');

// ...

$.container.add(d.getView());

How come drawer.xml have a view with id=container added within main.xml which also have a view with a id=container ?

Is this ok ?

how could you access second #container form main controller?

网友答案:

In case which you are describing two different views are dynamically combined together but ids are accessible through different objects: $ for main.xml and d for drawer.xml.

So for example you can access:

  • <View id="container"> from drawer.xml by:
    d.container

  • <View id="content"> from main.xml by:
    $.content

  • <View id="container"> from main.xml by:
    $.container

相关阅读:
Top