mmdc
mmdc

Reputation: 1746

how to count number of items in repeated values?

I got a repeated values which are sent from controller. I used it like it in view like this:

<select name="subcategory">
@repeat(data("sub_categories")) { i =>
    <option value="@i("id").value">@i("name").value</option>
}
</select>

Now I want to count to get number of items in data("sub_categories") How can I do that?

I tried data("sub_categories").length or data("sub_categories").value.length, both do not work.

Thanks

Upvotes: 0

Views: 87

Answers (1)

Rado Buransky
Rado Buransky

Reputation: 3294

data is a Form and data("sub_categories") is of type Field so for a repeated item you should be able to get number of items by calling data("sub_categories").indexes.length

Upvotes: 1

Related Questions