Detecting the presence of a value in a query returned from server connect in app connect

I have always done things like this at server connect level but I find myself looking for an APP CONNECT alternative

I have a multi record query which returns fields containing a letter

  • query:[
    • {
      • item_code: “B”},
    • {
      • item_code: “C”},
    • {
      • item_code: “F”},
    • {
      • item_code: “A”},
    • {
      • item_code: “D”},
    • {
      • item_code: “E”}]
        }

I am looking for the best way to detect if, say the value “E” is contained in the query.
even better still would be if the letters either “E” or “D” (i know I could repeat the condition with an OR if necessary)

have played around with where() and contains() but don’t seem to be able to get this to work properly, sure it is simple but getting frustrated.

You can use the inArray condition in the where formatter:

serverconnect1.data.query.where(`item_code`, ['E','D'], 'inArray')

or maybe check the count:

serverconnect1.data.query.where(`item_code`, ['E','D'], 'inArray').count()

so if there are no matches it will return 0, which is false.

Thanks, never thought of inarray()
BUT

<p dmx-text="serverconnect1.data.query.where(`item_code`, ['E','D'], 'inArray').count()"></p>

returns


in the dev console

App connect etc are loaded in the layout page and linked in content

Layout:

<head>
  <base href="/">
  <script src="/dmxAppConnect/dmxAppConnect.js"></script>
  <meta charset="UTF-8">
  <title>wheretest</title>

  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css" integrity="sha384-HzLeBuhoNPvSl5KYnjx0BT+WB0QEEqLprO+NBkkk5gbc67FTaL7XIGa2w1L0Xbgc" crossorigin="anonymous" />
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="stylesheet" href="/bootstrap/5/css/bootstrap.min.css" />
  <link rel="stylesheet" href="/css/style.css" />
  <script src="/dmxAppConnect/dmxRouting/dmxRouting.js" defer></script>
  <link rel="stylesheet" href="/dmxAppConnect/dmxNotifications/dmxNotifications.css" />
  <script src="/dmxAppConnect/dmxNotifications/dmxNotifications.js" defer></script>
  <script src="/dmxAppConnect/dmxBrowser/dmxBrowser.js" defer></script>
</head>

Content:

<!-- Wappler include head-page="layouts/main" fontawesome_5="cdn" bootstrap5="local" is="dmx-app" id="getitems" appConnect="local" components="{dmxFormatter:{}}" -->

Bug?

I think the formatter js is missing from your page.

nope, can see it (working locally with Wappler server)

image

I mean the include is missing from your page :slight_smile: inside the head tags

:exploding_head:
Damit, hate it when you are right, which is every time!

3 Likes