【发布时间】:2014-03-10 05:43:32
【问题描述】:
我使用这个 StackOverflow 问题 (how to handle votes in ember.js?) 中的 jsFiddle (http://jsfiddle.net/chopper/GgGGD/22/) 将上下投票添加到我的 Ember 网站。就像在这个小提琴中一样,我所有的数据都保存在我的 app.js 中,我没有支持的数据库。
上下投票有效,但不会保存该数据,因此会在页面刷新时重置。非常感谢有人支持时如何保存更改的任何帮助!
控制器
App.ThemeController = Ember.ObjectController.extend({
actions: {
voteUp: function () {
console.log("voting up");
this.set('votes', this.get('votes') + 1);
},
voteDown: function () {
console.log("voting down");
this.set('votes', this.get('votes') - 1);
}
}
});
数据
App.THEMES = [
{
id: 1,
title: 'Decode',
price: '$0',
free: true,
description: 'A minimal, modern theme, designed to be mobile first and very responsive, Decode is built just for Ghost and uses Ghost\'s innovative features to present a beautiful and clean blog.',
columns: 1,
popular: true,
purchaseLink:'https://github.com/ScottSmith95/Decode-for-Ghost',
demoLink:'http://decode-ghost-demo.scotthsmith.com',
image: 'images/decode.jpg',
votes: 0
}, ....
谢谢, 大卫·B
【问题讨论】:
-
您可以使用 Ember 的 incrementProperty 和 decrementProperty 来简化您的代码。更多信息在这里:emberjs.com/guides/cookbook/working_with_objects/…
标签: javascript ember.js