簡體   English   中英

在EMber.js中觀察其他控制器的屬性

[英]Observing a property of a different controller in EMber.js

我想觀察其他控制器中某個控制器的屬性,如何實現呢?

App.ApplicationController=Ember.Controller.extend({
    isLoading:false
});
App.MypageController=Ember.Controller.extend({
    isLoading:function(){
    //I want this property to observe the isLoading property in the Application controller 
    //so that I can show certain part of mypage template only when isLoading in application
    //controller is false
    }
});

目前無法測試,但您可以嘗試一下

App.ApplicationController = Ember.Controller.extend({
    needs: ['page'],
    page: Ember.computed.alias("controllers.page")
    isLoading:function(){
        return page.get('isLoading');
    }
});

盡管考慮到這一點,這可能會阻塞應用程序控制器,但還不夠確定。 並且可能會有更好的方法來知道控制器是否已加載。

暫無
暫無

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

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