英文:
Filter available apps by key
问题
我正在获取设备上安装的应用程序数量,如何筛选它们以仅包括键google_maps和apple_maps?
应用程序列表:
mapsAppInfo = {
baidu: false,
cabify: false,
citymapper: false,
ee.mtakso.client: true,
gaode: false,
google_maps: true,
here_maps: false,
lyft: false,
maps_me: false,
moovit: false,
sygic: false,
taxis_99: false,
uber: true,
waze: false,
yandex: false
}
useEffect(() => {
const loadAvailableMapApps = async () => {
const mapsAppInfo = (await launcNavigator.getAvailableApps()) as AppInfo;
const availableApps = Object.keys(mapsAppInfo).filter(
(key) => mapsAppInfo[key],
);
setAvailableMapApps(availableApps);
};
// eslint-disable-next-line no-void
void loadAvailableMapApps();
}, []);
英文:
I am getting the number of apps installed on device, how can I filter them to only include the keys, google_maps and apple_maps ?
List of apps:
mapsAppInfo = {
baidu: false
cabify: false
citymapper: false
ee.mtakso.client: true
gaode: false
google_maps: true
here_maps: false
lyft: false
maps_me: false
moovit: false
sygic: false
taxis_99: false
uber: true
waze: false
yandex: false
}
useEffect(() => {
const loadAvailableMapApps = async () => {
const mapsAppInfo = (await launcNavigator.getAvailableApps()) as AppInfo;
const availableApps = Object.keys(mapsAppInfo).filter(
(key) => mapsAppInfo[key],
);
setAvailableMapApps(availableApps);
};
// eslint-disable-next-line no-void
void loadAvailableMapApps();
}, []);
答案1
得分: 1
最简单的方法可能是在您的情况下手动筛选它们。您可以在已有的筛选器之前添加另一个筛选器:
const availableApps = Object.keys(mapsAppInfo)
.filter(k => (k === "google_maps" || k === "apple_maps"))
.filter(
(key) => mapsAppInfo[key],
);
英文:
The easiest way would probably be to filter them by hand in your case. You can add another filter before the one you already have:
<!-- language: lang-js -->
const availableApps = Object.keys(mapsAppInfo)
.filter(k => (k === "google_maps" || k === "apple_maps")
.filter(
(key) => mapsAppInfo[key],
);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论