1

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);
}

1 Answer 1

1

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.

1
  • In the index.js, I cannot find updateLabel. When break in the index.js file, v.updateLabel is undefined Mar 3, 2014 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.