export default DS.Model.extend({
initValue : attr('number', {
defaultValue: 0
}),
value: attr('number', {
defaultValue: function() {
var val = 0;
this.get('operations').forEach(function(operation) {
val += operation.get('value');
});
return this.get('initValue') + val;
}.property('operations.@each.value') // <- ошибка, так делать не надо
}),
operations: DS.hasMany('operation', {
async: true
})
});
export default DS.Model.extend({
initValue : DS.attr('number', { defaultValue: 0 }),
operations: DS.hasMany('operation', { async: true }),
value: function() {
var val = 0;
this.get('operations').forEach(function(operation) {
val += operation.get('value');
});
return this.get('initValue') + val;
}.property('operations.@each.value', 'initValue'),
});
export default Ember.Route.extend({
model: function () {
return this.store.findAll('task').then(function(tasks){
return tasks.filterBy('state', 'done');
});
}
});
export default Ember.Component.extend({
filtredData: function() {
return this.get('data').filterBy(this.get('filterKey'), this.get('filterValue'));
}.property('data', 'filterKey', 'filterValue')
});
app/adapters/application.js
export default EmberCouchDBKit.DocumentAdapter.extend({
db: ...,
host: ...
});
cities: function() {
//Получаем список городов которые есть в памяти
var cities = this.store.all('city');
//Если города еще не загружались, берем их с сервера.
if (!cities.length) {
cities = this.store.find('city');
}
return cities;
}.property()
{{view "select"
content=cities
optionValuePath="content.id"
optionLabelPath="content.name"
value=session.user.cityId}}
{
"mainmodel": {
"id": 1,
"simplefield": "string",
"complexfield": 2
},
"complexfield": {
"id": 1,
"name": "somename"
}
}
complexfield: DS.belongsTo('complexfield', {async: true})
App.IndexRoute = Ember.Route.extend({
model: function() {
return App.Item.all();
}
});
App.Item.reopenClass({
all: function() {
return $.getJSON("http://domain.com/data.php").then(function(response) {
return response;
});
}
});
App.Item.reopenClass({
all: function() {
return $.getJSON("http://domain.com/data.php").then(function(response) {
return response.forEach(function(item){
return App.Item.create(item);
});
});
}
});
App.EditorTabsComponent = Ember.Component.extend({
didInsertElement: function() {
var _this = this;
Ember.RSVP.Promise.resolve(this.get('data')).then(function(chartData) {
App.Tabs = _this.$().tabs();
App.Tabs.tabs('refresh');
});
},
});
App.XNodeComponent = Ember.Component.extend({
contextMenuInit: function() {
this.$().contextmenu({
delegate: ".hasmenu",
menu: [
{title: "Copy", cmd: "copy", uiIcon: "ui-icon-copy"},
{title: "----"},
{title: "More", children: [
{title: "Sub 1", cmd: "sub1"},
{title: "Sub 2", cmd: "sub1"}
]}
],
select: function(event, ui) {
console.log("select " + ui.cmd + " on " + ui.target.text());
}
});
}.on('didInsertElement')
});
{{x-node}}