Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Alloy: Passing $model to controller and data binding

$
0
0

I'm trying to get passing a model through $model to work to allow for simple data binding.

My calling controller does:

var lvlObj = Alloy.createModel("level");
    lvlObj.fetch({id:currentlvl});
    var newLevelController = Alloy.createController("newlevel",{$model:lvlObj,playcontroller:$});
    var nlView = newLevelController.getView();
level.xml:
<Label id="lvlname" text="{label}"/>
Label is an attribute of the level model.

When I run this I get an error:

"'undefined' is not an object (evaluating '$model.__transform[\"label\"]')";
However, if I change my level.xml to:
<Model src="level" id="levelObj" instance="true" />
<Label id="lvlname" text="{$.levelObj.label}"/>
add in my level.js do:
$.levelObj.set($model);
It WORKS! But I want to better understand why the first approach doesn't work.

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>