按关键字筛选可用的应用程序

huangapple go评论64阅读模式
英文:

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 =&gt; (k === &quot;google_maps&quot; || k === &quot;apple_maps&quot;)
    .filter(
        (key) =&gt; mapsAppInfo[key],
    );

huangapple
  • 本文由 发表于 2023年7月10日 22:09:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76654586.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定