我如何确定 Observable 是否从未收到任何东西?
How do I determine, if Observable has never received anything?
如何确定 Observable 是否 "empty"?
更好的是,它从未收到任何东西。
我的代码如下所示:
spots: Observable<Spot[]>;
我已经尝试了在 Google 上发现的一些东西,例如:
spots.isEmpty();
spots.length;
spots.length();
spots().length;
spots.first();
但是 none 他们的工作方式如我所愿..
我需要这个功能,用 No items found
填充 Ionic2 中的列表,直到加载第一个项目。
我在代码中是这样解决的:
if ( arrayOfItems && arrayOfItems.length > 0 ) {
// display the list
return arrayOfItems.map((item) => { return item; })
} else {
// show a message that nothing was found
return "Nothing to see here...";
}
这将检查变量是否具有某种正值(即它不是 null
、false
或 undefined
)并且数组至少有一个值.如果不是这种情况,则显示一条消息,说明未找到任何内容。
我是这样解决的:
我有一个变量 let isEmpty=true;
,当我收到 Observable
:
中的第一个对象时,将其设置为 false
spots.subscribe(() => {
this.empty = false;
...
});
如何确定 Observable 是否 "empty"? 更好的是,它从未收到任何东西。
我的代码如下所示:
spots: Observable<Spot[]>;
我已经尝试了在 Google 上发现的一些东西,例如:
spots.isEmpty();
spots.length;
spots.length();
spots().length;
spots.first();
但是 none 他们的工作方式如我所愿..
我需要这个功能,用 No items found
填充 Ionic2 中的列表,直到加载第一个项目。
我在代码中是这样解决的:
if ( arrayOfItems && arrayOfItems.length > 0 ) {
// display the list
return arrayOfItems.map((item) => { return item; })
} else {
// show a message that nothing was found
return "Nothing to see here...";
}
这将检查变量是否具有某种正值(即它不是 null
、false
或 undefined
)并且数组至少有一个值.如果不是这种情况,则显示一条消息,说明未找到任何内容。
我是这样解决的:
我有一个变量 let isEmpty=true;
,当我收到 Observable
:
spots.subscribe(() => {
this.empty = false;
...
});