Vue: Use v-for directive to store items without matches in a separate container

Currently, I am in the process of creating an application similar to Trello.
My setup involves using a user_list for categories and ticket_list for items within each category.
Each item in the ticket_list is linked to a user's id in the user_list.

One feature I would like to implement is having a static field called UNASSIGNED, where I can move all items from the ticket_list that do not have a corresponding user_id in the user_list.

This is what my code looks like....

<div class="static_ticket_category">
         <span>Unassigned</span>
    </div>
<div v-for="user in user_list" :key="user_index">
    <div class="ticket_category">
        <span>{{user.name}}</span>
    </div>

    <div class="ticket_items">
        <div v-for="item in ticket_list">
            <draggable .....>
                <template v-if="item.user_id == user.id">
                    <v-card>
                          ...content goes here
                    </v-card>
                </template>
            </draggable>
        </div>
    </div>
</div>

The current code functions correctly... however, it does not display items with no user id associated.
I am wondering if there is a way to automatically assign these unlinked items to the Unassigned category?

Answer №1

To accomplish this task, you can create a computed property.

<span>No Assignments</span>
<div v-for="item in unassigned_items">{{ item }}</div>

Next, add the following code:

computed: {
  unassigned_items: function () {
    return this.task_list.filter(function (task) {
         return task.assignee_id === 0             
    })
  }
}

Answer №2

One possible solution is to create a computed property that combines unassigned tickets with an unassigned user and links the tickets with the respective users.

computed: {
    usersWithTicketList () {
        // merge users and tickets into one object
        let users = this.user_list.map(user => {
            let tickets = this.ticket_list.filter(ticket => ticket.user_id === user.id)
            return {...user, tickets}
        })

        // add unassigned tickets to a fake user
        users.concat({
            id: -1, // fake user id for unassigned
            // other user info
            tickets: UNASSIGNED
        })

        return users
    }
}

Subsequently, your template would have a structure similar to the following:

<div v-for="user in usersWithTicketList" :key="user.id">
    <div v-for="item in user.tickets" :key="ticket.id">
        <v-card>
            <!-- Since we have linked each ticket to a user including the unassigned category, there is no need for a conditional check here -->
        </vcard>
    </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

An alternative method to confirm the checkbox selection without physically clicking on it

Currently, I'm in the process of creating a basic to-do list and have been attempting to connect the task with its corresponding checkbox. My goal is for the checkbox to automatically be checked when the task is clicked. Instead of using HTML to add ...

The absence of 'let' or 'var' in an ES6 class leads to an undefined variable

The issue arises when utilizing the ES6 class syntax, as a variable within a method declared without 'let' or 'var' becomes undefined. On the other hand, in the case of regular object syntax, the variable is indeed defined. To demonstr ...

Using a v-for to dynamically generate srcset properties

While I may be lacking some fundamental vue.js knowledge, I have a specific question regarding the <picture> element and more specifically, the srcset attribute. My API provides me with different formats of the same image as follows: "posts": [ { ...

Angular - Implementing service worker to extract dynamic ID from route in "Notificationclick" event?

I have integrated push notifications into my code to notify users when an action is taken. The backend was developed using lib.net.webpush 3.1.0 with .net 4.5.2 in C#. The notification system is functioning well, but I am facing a challenge: Within my ser ...

Generate Random Messages in a pop-up window using window.alert functionality in Javascript

As a first-year Digital Arts student, I have been tasked with creating a basic E-Learning website for mathematics. The concept is simple - the user is asked to solve math problems like "What is 7 times 7?", enters their answer, clicks a button, and an aler ...

Incorporate dynamic JavaScript content within an HTML document

Currently, I am facing an issue with a webpage that I need to load in order to extract some information. Using HttpClient and Jsoup worked well for loading the majority of the content on the page. However, my problem lies with certain elements that are onl ...

I am experiencing difficulties in generating a React application using "create-react-app"

Here is the error message from the console: > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="04676b7661296e7744362a322a35">[protected email]</a> postinstall G:\mernbootcamp\testfront\my-app\node ...

The link containing special characters like % cannot access the api

I am facing an issue with retrieving a signUrl from S3. When I make the call with special characters like %, my code does not parse it correctly and I receive a 404 not found error. Here is the ajax request I am using: My API setup: app.get('/websi ...

Using ESLint to enforce snake_case naming conventions within TypeScript Type properties

When working with TypeScript, I prefer to use snake_case for properties within my Interfaces or Types. To enforce this rule, I have configured the ESLint rule camelcase as follows: 'camelcase': ["error", {properties: "never"}], Even though the E ...

Guide to embedding bootstrap.min.js into ember-bootstrap extension

I'm currently experiencing an issue with the ember-bootstrap plugin. Following the instructions on their setup page at , I downloaded and installed it. Once I began working on the Navbar, I encountered a problem. The Hamburger menu, which is supposed ...

Attaching a function to the "onselect" event that manages the character limit within an input text field

I have been developing a function to restrict the number of characters a user can enter into a text field. Here's what I have so far: $.fn.restringLength = function (id, maxLen) { $(id).keypress(function(e){ var kCode = ...

Issue with Angular 2 pipe causing unexpected undefined result

Here is a JSON format that I am working with: [{ "id": 9156, "slug": "chicken-seekh-wrap", "type": "dish", "title": "Chicken Seekh Wrap", "cuisine_type": [2140] }, { "id": 9150, "slug": "green-salad", "type": "dish", "title": "Green Sala ...

Comparing global variables in ng-switch: Best practices

I'm currently utilizing the AngularJS $rootScope object to expose some global constants that should be accessible to both controllers and views: var app = angular.module('myApp', []); app.run(function ($rootScope) { $rootScope.myConsta ...

"Exploring In-Depth Data Visualization: A Guide to Navigating Charts

It was shocking to me how scarce the information on this subject is. I have a ChartJS pie chart that I would like to delve deeper into by clicking on a slice of the pie. Do you have any suggestions on how to achieve this? ...

Setting up secure HTTPS connections for Node.js and Vue.js

I am encountering an issue with my Laravel and Vue.js site, which also utilizes nodejs. Accessing the site via http works fine, but when attempting to use https, half of the site fails to load and I receive the following error in the console: Access to XML ...

Triggering of NVD3 Angular Directive callback occurring prematurely

Lately, I've delved into utilizing NVD3's impressive angular directives for crafting D3 charts. They certainly have a sleek design. However, I'm encountering numerous challenges with callbacks. While callbacks function smoothly when incorpor ...

Vue verifies the readiness of two computed properties

Each time I want to determine when multiple computed values are ready, I create another computed property like isFizzAndBuzzReady. computed: { fizz () { return ['f', 'i', 'z', 'z'] // asynchronous data retriev ...

Looking for guidance on how to initiate or halt React Native Moti animation when the state changes? I've been running into issues where my method appears to disrupt

While experimenting with the Moti animation, everything was working perfectly until I included the playbackState === State.Playing condition. Unfortunately, once I added it, the animation looped only once and then stopped repeating. I'm puzzled as to ...

"Why is it that when using jQuery, the .fail method doesn't accept arguments to deliberately

I am attempting to utilize custom JSON encoded data after intentionally triggering an error on the server (throwing an error on purpose) during a jQuery AJAX request. I am confused as to what is going wrong, as the header is correct and the data is being ...

How can I activate the socket.io connection event in NodeJS?

I'm currently experimenting with socket.io on NodeJS and I am facing a challenge in figuring out how to activate the socket solely from NodeJS. Previously, I have been using socket.io by invoking it from the front end. However, I am curious if it is ...