Answer the question
In order to leave comments, you need to log in
property() method of function class in ember.js
There are two examples of using function(){}.property() in the documentation
:
Example 1:
MyApp.President = Ember.Object.extend({
firstName: '',
lastName: '',
fullName: function() {
return this.get('firstName') + ' ' + this.get('lastName');
// Call this flag to mark the function as a property
}.property()
});
var president = MyApp.President.create({
firstName: "Barack",
lastName: "Obama"
});
president.get('fullName');
MyApp.President = Ember.Object.extend({
firstName: '',
lastName: '',
fullName: function() {
return this.get('firstName') + ' ' + this.get('lastName');
// Tell Ember.js that this computed property depends on firstName
// and lastName
}.property('firstName', 'lastName')
});
Answer the question
In order to leave comments, you need to log in
It's clearly written there.
Many computed properties have dependencies on other properties. For example, in the above example, the fullName property depends on firstName and lastName to determine its value. You can tell Ember about these dependencies like this:
Let's take the first example.
If do:
var president = MyApp.President.create({
firstName: "Barack",
lastName: "Obama"
});
president.get('fullName');
Will return "Barach Obama"president.set('firstName', 'George');
president.set('lastName', 'Washington');
president.get('fullName');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question