【问题标题】:Appcelerator Titanium Alloy | How to access element of other classAppcelerator 钛合金 |如何访问其他类的元素
【发布时间】:2015-10-08 12:52:17
【问题描述】:

在 Alloy Titanium 中,我可以使用其 id $.element_id 访问 XML 元素,但是如何获取其他类的元素?还是xml?

编辑

我有两个文件。 1.file1.js、file1xml.xml 2.file2.js、file2xml.xml

在 File1.js 中,我想访问 file2xml.xml 的变量。我怎样才能做到这一点?

【问题讨论】:

    标签: titanium titanium-mobile titanium-alloy


    【解决方案1】:

    任何有 id 的东西都可以访问:

    file1.xml

    <Alloy>
      <View id="myView" />
    </Alloy>
    

    file2.js

    var ctrl1 = Alloy.createController('file1');
    ctrl1.myView.backgroundColor = 'red';
    

    【讨论】:

      【解决方案2】:

      如果您在 file1.xml 中需要 file2.xml,例如

      <Require src="common/viewToolBar" id="viewToolBar"/>
      

      那么你就可以在file1.js中获取带有id的元素了

      $. viewToolBar.getView('viewSynch').visible = false;
      

      link了解更多详情

      【讨论】:

        【解决方案3】:

        您可以在带有 Id 的合金中使用 Require 标签,并且可以按如下方式访问其元素。

        **File1.xml**
        
        <Alloy>
        <View>
            <Label id="labelId">Middle</Label>
        </View></Alloy>
        
        
        **File2.xml**
        
        <Window>
            <Require src="File1" id="File1View" type="View"/>
            <View id="header"><Label id="headerText">Header</Label></View>
            <View id="nav">
                <Label class="navButton" onClick="openTab" controllerName="home">Home</Label>
                <Label class="navButton" onClick="openTab" controllerName="news">News</Label>
                <Label class="navButton" onClick="openTab" controllerName="info">Info</Label>
                <Label class="navButton" onClick="openTab" controllerName="more">More</Label>
            </View>
        </Window> 
        
        **File2.js**
        
        $.File1View.labelId.text = "hi";
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-10-31
          • 2015-12-30
          • 1970-01-01
          • 1970-01-01
          • 2020-10-29
          • 1970-01-01
          • 2017-08-04
          • 2014-12-13
          相关资源
          最近更新 更多