我正在Ember.js中构建一个应用程序,并且遇到监视我向用户显示的属性的问题。当用户登录时,我正在查询一个API,以获得具有名为“isTrue”的字段的消息数量并查看有多少个值为“true”。Ember.js控制器属性问题
当用户登录到系统中我从他们的Cookie在应用控制器通过在init抓一个ID:
该数据然后被显示在应用程序模板函数()。这是做这件事的最好方法吗?我有一个问题,当用户单击按钮将记录从“isNew”==“true”更改为“isNew”==“false”时,该属性未正确更新。这是做这件事的最好方法,还是我从Ember的角度来看它是错误的?
App.ApplicationController = Ember.Controller.extend({
messageCount: null,
init: function() {
var test = 0;
//get the cookie
//query an API to retrieve a set of records to check if a specific field is marked as true
//Compute the messageCount based on the number of records that are marked as true and set test equal to the message count.
this.set("messageCount", test);
getMessages: function() {
//repeat the code from the init function
}
actions: {
markAsRead: function() {
getMessages();
}
}
})
'isNew'在哪里玩?当你点击行动'markAsRead'?财产(我猜'messageCount')如何得到更新,只有在客户端或服务器上?我想我只是没有看到你试图更改记录的位置...... – Hana
@Hana'isNew'存储在服务器上,每次用户登录时都会通过API查询或者他们将消息标记为已读通过传播到markAsRead函数的操作。 – datapanda