我有一个加载模板,我想在其中随机显示"请等待"每次使用加载路径时都会显示消息,但是当随机性第一次起作用时,属性会被设置并且不会刷新。每次加载路径时如何返回随机值?
我尝试创建一个timestamp属性并将其添加到监视字段,但同样,该属性只设置一次然后不刷新。我也试过添加" Date()"在观察名单中,它确实不那样(可以理解,因为它不是一个领域)。
这是我的加载控制器代码: 从' ember';
导入Ember//app/controllers/loading.js
export default Ember.ObjectController.extend({
loadingText: [
'Your wish is my command.',
'Loading, please hang on.',
'I\'ll be back in two shakes of a lamb\'s tail.',
'Your request is very important to us...',
'Hmmmm hmm hmmm...',
'It shall be as you say...',
'Let me get that for you.'
],
randLoadingText: Ember.computed('loadingText', function() {
var loadingText = this.loadingText;
return (loadingText[Math.floor(Math.random()*loadingText.length)]);
})
});
答案 0 :(得分:4)
您是否尝试在属性上使用volatile选项?
//app/controllers/loading.js
export default Ember.ObjectController.extend({
loadingText: [
'Your wish is my command.',
'Loading, please hang on.',
'I\'ll be back in two shakes of a lamb\'s tail.',
'Your request is very important to us...',
'Hmmmm hmm hmmm...',
'It shall be as you say...',
'Let me get that for you.'
],
randLoadingText: function() {
var loadingText = this.loadingText;
return (loadingText[Math.floor(Math.random()*loadingText.length)]);
}.property().volatile()
});