0

I'm building an application in Ember.js and I'm having an issue monitoring a property I'm displaying to the user. When the user logs in I'm querying an API to get the count of the number of message that have a field called "isTrue" and seeing how many have a value of "true".

When the user logs into the system I am grabbing an ID from their cookie in the application controller through the init: function()

This data is then being displayed in the Application Template. Is this the best way to do this? I'm having an issue that when the user clicks on a button to change the record from "isNew" == "true" to "isNew" == "false" the property is not updating correctly. Is this the best way to do this or am I going about it all wrong from an Ember standpoint?

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();
        }
    }

})
4

1 回答 1

0

在这个简单的待办事项列表示例中检查他们如何跟踪已完成任务的数量。

你应该设置你的财产是这样的:

messageCount: function () {
    return this.filterProperty('isNew', true).get('length');
}.property('path.to.my.messages.array.@each.isNew'),

现在不需要手动设置,它会自动更新。

于 2013-10-25T23:31:29.553 回答