如何缓慢传递 ember 组件重复的数据列表
How to slowly pass ember component a repeating list of data
嘿,所以我想轮流传递一个组件不同的数据,所以说我的控制器中有几个对象 class
a: {
name: "a",
number: 6
}
b: {
name: "b",
number: 15
}
我想将它们传递给模板文件中的组件:
{{my-component data=a}}
但是我想通过我的组件循环传递数据,数据 'a' 显示 4 秒,然后 'b' 的数据显示 4 秒,然后连续重复此操作直到页面已更改。关于我如何做到这一点的一些想法,我已经尝试过但没有奏效。
使用 Ember.run.later 并尝试调用该函数(我收到 'self.function()' 不是函数的错误(注意这是在控制器的操作部分,当您单击时它开始旋转一个按钮。):
function: function(){
var self = this;
return self.get('test');
Ember.run.later((function() {
if(self.get('test'))
self.set('test', false);
else
self.set('test', true);
self.function(); // <-- Error is here
}), 4000);
}
然后在模板中使用 if 语句:
{{#if test}}
{{my-component data=a}}
{{else}}
{{my-component data=b}}
{{/if}}
所以它是第一次运行这个,但它实际上从未在这两个数据项之间循环。
非常感谢帮助。
您可以只更改传递给组件的数据。
{{my-component data=selectedObject}}
在您的控制器中:
selectedObject: {},
count: 0,
allObjects: [
{
name: "a",
number: 6
},
{
name: "b",
number: 6
}
],
rotateObject: function() {
this.set('selectedObject', this.get('allObjects')[count]);
this.set('count', this.get('count')+1);
Ember.run.later(function(){
this.rotateObject();
},4000);
}
这样,selectedObject 将每 4 秒更改一次,组件将使用新数据进行更新。
我将对象更改为 array.I 我相信你能想出办法。
嘿,所以我想轮流传递一个组件不同的数据,所以说我的控制器中有几个对象 class
a: {
name: "a",
number: 6
}
b: {
name: "b",
number: 15
}
我想将它们传递给模板文件中的组件:
{{my-component data=a}}
但是我想通过我的组件循环传递数据,数据 'a' 显示 4 秒,然后 'b' 的数据显示 4 秒,然后连续重复此操作直到页面已更改。关于我如何做到这一点的一些想法,我已经尝试过但没有奏效。
使用 Ember.run.later 并尝试调用该函数(我收到 'self.function()' 不是函数的错误(注意这是在控制器的操作部分,当您单击时它开始旋转一个按钮。):
function: function(){
var self = this;
return self.get('test');
Ember.run.later((function() {
if(self.get('test'))
self.set('test', false);
else
self.set('test', true);
self.function(); // <-- Error is here
}), 4000);
}
然后在模板中使用 if 语句:
{{#if test}}
{{my-component data=a}}
{{else}}
{{my-component data=b}}
{{/if}}
所以它是第一次运行这个,但它实际上从未在这两个数据项之间循环。 非常感谢帮助。
您可以只更改传递给组件的数据。
{{my-component data=selectedObject}}
在您的控制器中:
selectedObject: {},
count: 0,
allObjects: [
{
name: "a",
number: 6
},
{
name: "b",
number: 6
}
],
rotateObject: function() {
this.set('selectedObject', this.get('allObjects')[count]);
this.set('count', this.get('count')+1);
Ember.run.later(function(){
this.rotateObject();
},4000);
}
这样,selectedObject 将每 4 秒更改一次,组件将使用新数据进行更新。 我将对象更改为 array.I 我相信你能想出办法。