簡體   English   中英

Ember.js控制器屬性問題

[英]Ember.js Controller Property Issue

我正在Ember.js中構建應用程序,並且在監視顯示給用戶的屬性時遇到問題。 當用戶登錄時,我正在查詢一個API,以獲取具有名為“ isTrue”的字段的消息數的計數,並查看有多少消息的值為“ true”。

當用戶登錄到系統時,我正在通過init從應用程序控制器中的cookie中獲取一個ID:function()

然后,該數據將顯示在應用程序模板中。 這是最好的方法嗎? 我遇到一個問題,當用戶單擊按鈕以將記錄從“ 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();
        }
    }

})

在這個簡單的“待辦事項列表”示例中,檢查他們如何跟蹤已完成任務的數量。

您應該將屬性設置如下:

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

現在無需手動設置,它將自動更新。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM