gpt4 book ai didi

ember.js - Ember :每次重载时返回随机属性值

转载 作者:行者123 更新时间:2023-12-02 05:59:48 24 4
gpt4 key购买 nike

我有一个加载模板,在该模板中,每次使用加载路线时,我都希望显示一条随机的“请稍候”消息,但是当随机性第一次起作用时,该属性便会设置并且不会刷新。每次加载路线后,如何返回随机值?

我尝试创建一个timestamp属性,并将其添加到监视的字段中,但是同样,该属性仅设置一次,然后不刷新。我还尝试将“Date()”添加到监视列表中,但实际上不喜欢这样(可以理解,因为它不是字段)。

这是我的加载 Controller 代码:
从“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)]);
})
});

最佳答案

您是否尝试对属性使用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()
});

关于ember.js - Ember :每次重载时返回随机属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26845765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com