Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stages from array of objects instead of strings #24

Open
jfdelarosa opened this issue Feb 6, 2019 · 6 comments
Open

Stages from array of objects instead of strings #24

jfdelarosa opened this issue Feb 6, 2019 · 6 comments

Comments

@jfdelarosa
Copy link

Is it possible to render the board with the stages made of an array of objects instead of an array of strings?

I mean, something like this:

stages: [{
  name: "Stage 1",
  id: 1
}, {
  name: "Stage 2",
  id: 2
}, {
  name: "Stage 3",
  id: 3
}]

Instead of:

stages: ["Stage 1", "Stage 2", "Stage 3"]

My structure is the following:

<kanban-board :stages="stages" :blocks="blocks">
    <div v-for="stage in stages" :slot="stage">
        <h2>{{ stage.name }}</h2>
    </div>
    <el-card v-for="block in blocks" :slot="block.id">
        <div><strong>id:</strong>{{ block.id }}</div>
        <div>{{ block.title }}</div>
    </el-card>
</kanban-board>

This is the result:
image

https://screencast.com/t/NTcrSUWqe
Thanks!

@jfdelarosa jfdelarosa changed the title Stage as object Stages from array of objects instead of strings Feb 6, 2019
@atmonshi
Copy link

atmonshi commented Jun 9, 2019

@jfdelarosa have you find a solution for this ?

@BrockReece
Copy link
Owner

Couldn't you just create a computed property for getting the array of objects in the correct shape?
Just off the top of my head?

stageNames () {
  return this.stages.map(stage => stage.name)
}

@atmonshi
Copy link

atmonshi commented Jun 10, 2019

It’s will work , but in my case I needed the Object to get more data like the icon and the color of each stage from the DB

<div v-for="stage in stages" :slot="stage" :key="stage" :style="{ color: stage.color }"> <h2> <i class="fas" :class="'fa-'+stage.icon"></i> {{ stage }} </h2> </div>

I wish if there is a simpler way than the computed property .

@BrockReece
Copy link
Owner

Sure but then you can pass the array of stageNames to the kanban component and use the original stages array for building the slots, right?

Something like this should work?

<Kanban :stages="stageNames" :blocks="blocks">
  <div v-for="stage in stages" :slot="stage.name" :key="stage.name" :style="{ color: stage.color }"> 
    <h2>
      <i class="fas" :class="'fa-'+stage.icon"></i>
      {{ stage.name }}
    </h2>
  </div>
</Kanban>

@jfdelarosa
Copy link
Author

Unfortunately, I leaved the project in wich I used this component.

@BrockReece that is the most logical solution, unfortunately it didn't work, I can't remember why :/
I think @wa7eedem solution should do the trick, never tried that way but it seems logic.

@BrockReece
Copy link
Owner

@jfdelarosa I tried my suggestion above and it seemed to work.
What is @wa7eedem's solution?

I can't think of a way of refactoring this without making breaking changes or adding a tonne of v-ifs
I think if we were going to do that, we should probably move to a scoped slot solution anyway, this component was built before Vue had scoped slots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants