Skip to content
This repository has been archived by the owner on May 3, 2018. It is now read-only.

Access array property in v-repeat #12

Closed
malkomalko opened this issue Mar 27, 2014 · 5 comments
Closed

Access array property in v-repeat #12

malkomalko opened this issue Mar 27, 2014 · 5 comments

Comments

@malkomalko
Copy link

I know this is a strange request.

var a = [[1,2,3],[4,5,6]]
a[0].batch = 1
a[1].batch = 2

Is there anyway to access the .batch field on an array? I tried $value.batch but that doesn't seem to work. Sometimes I want to store some data on an array instance when run through a filter.

@yyx990803
Copy link
Member

hmm properties attached to Arrays are not observed. Also when you pipe an Array through filters what you get in the end might not be the original Array.

If you have control over the structure, just use objects to wrap them, e.g { numbers: [1,2,3], batch: 1 }

@malkomalko
Copy link
Author

Problem is I'm grouping items by date, and since object keys are not sorted I need to sort the group and output an array of arrays.

@yyx990803
Copy link
Member

What does your raw data look like? Is it possible to use orderBy filter on it?

@malkomalko
Copy link
Author

// somewhere in my filter

items[0].__date__ = day

// in my view

<h2>{{$value[0].__date__}}</h2>

this isn't pretty but it works.

As for my data: [[{}],[{}...]...]

Basically an array of arrays with objects.

@malkomalko
Copy link
Author

yah, just access a property on $value[0] is fine enough for me... I won't even mutate the array, just adding another filter.

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

No branches or pull requests

2 participants