Check if object is empty

  • Hello there,

    well - this seems to be so easy, but at the moment I'm having a dirty workaround.


    I got a computed property called "filteredItems". This "filteredItems" looks like this:


    Code
    1. { "7": { "url": false, "test": [], "id": 7, "status": 1, "slug": "dies-ist-ein-test", "title": "Dies ist ein Test" }, "8": { "url": false, "test": [], "id": 8, "status": 1, "slug": "zu-viele-items", "title": "Zu viele Items" }, "9": { "url": false, "test": [], "id": 9, "status": 1, "slug": "zu-viele-items-2", "title": "Zu viele Items - Copy" } }


    Or, if empty like this:


    Code
    1. {}


    Now I would like to show a text, if filteredItems is empty.


    But: The .length-method does not work here, so I can not do a simple


    Code
    1. <h3 class="uk-h1 uk-text-muted uk-text-center"
    2. v-show="!filteredItems.length">{{ 'No Items found.' | trans }}</h3>


    My dirty workaround is to check the length in the JS-file:

    Code
    1. if(Object.keys(result).length < 1) result = false;


    and do a


    Code
    1. <h3 class="uk-h1 uk-text-muted uk-text-center"
    2. v-show="!filteredItems">{{ 'No Items found.' | trans }}</h3>


    But this is not really elegant I think.