I have this code for view:
App.TodoView = Em.View.extend({
labelView: Em.TextField.extend({
}),
createNew:function () {
console.log(this.labelView.get('value'));
}
});
and this template:
{{#view App.TodoView}}
{{view labelView}}
{{#view Em.Button target="parentView" action="createNew"}}Add{{/view}}
{{/view}}
And I get the following error:
Uncaught TypeError: Object (subclass of Ember.TextField) has no method 'get'
I want to use insertNewLine method too, so I can set the value of the Em.TextField in template.
The problem is that you are defining a class and trying to get the
valuefrom it. What you rather want is to get thevalueof a concrete instance. This can be achieved by binding thevalueof theLabelViewto a value which can then be retrieved in theApp.TodoView, in this casetodoLabel, see http://jsfiddle.net/pangratz666/PTPsV/:Handlebars:
JavaScript:
Note that since you are defining a class
LabelViewit’s a convention to write it in Uppercase, whereas instances are written in lowerCase. See a good blog post about naming convention by The Emberist.Also, to access a property on an
Ember.Object, you should always useget, so it’sthis.get('todoLabel')and notthis.todoLabel.You can now implement further methods like
insertNewlineandcancel– note it’sinsertNewlineand notinsertNewLine, see text_support.The result would look like this, see http://jsfiddle.net/pangratz666/9ZLAC/: