Question

I am using Alloy 1.3. Can the content in the Controller.getView() can be updated? For example:

In Alloy, if we have view view.xml

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

In view.js

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

If I have another controller e.g. 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);
}
Was it helpful?

Solution

Updating content on object returned from controller.getView() method is fine. In your view.js example you can change label1 text in two different ways:

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

or

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

If you are calling $.getView() without any parameters it will return top level view which has the same id as name of your controller and view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top