【问题标题】:Can the content in Alloy Controller.getView() can be updated?Alloy Controller.getView() 中的内容可以更新吗?
【发布时间】:2014-02-18 10:36:21
【问题描述】:

我使用的是合金 1.3。 Controller.getView()中的内容可以更新吗?例如:

在 Alloy 中,如果我们有视图 view.xml

<Alloy>
   <View>
      <Label id="label1"/>
      ... other content ...
   </View>
</Alloy>

在 view.js 中

exports.updateLabel = function(value){
   $.label1.text = value;
}

如果我有另一个控制器,例如index.js

var v = Alloy.createController('view').getView();
// assume $.win is the <Window> in index.xml
$.win.add(v);

function updateContent(value){
   // This is not work. I want to know how it can be updated 
   // after the controller turned into a view
   v.updateLabel(value);
}

【问题讨论】:

    标签: view controller titanium appcelerator titanium-alloy


    【解决方案1】:

    更新从 controller.getView() 方法返回的对象的内容很好。在您的 view.js 示例中,您可以通过两种不同的方式更改 label1 文本:

    exports.updateLabel = function(value){
       $.label1.text = value;
    }
    

    exports.updateLabel = function(value){
       $.getView('label1').text = value;
    }
    

    如果您在没有任何参数的情况下调用 $.getView(),它将返回与控制器和视图名称具有相同 ID 的顶级视图。

    【讨论】:

    • 在 index.js 中,我找不到 updateLabel。在 index.js 文件中中断时,v.updateLabel 未定义
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多