Skip to content

Add a way to acceed to loop data#323

Open
bubbatls wants to merge 1 commit into
janl:masterfrom
bubbatls:patch-1
Open

Add a way to acceed to loop data#323
bubbatls wants to merge 1 commit into
janl:masterfrom
bubbatls:patch-1

Conversation

@bubbatls

Copy link
Copy Markdown

when using block {{#anArray}} {{/anArray}}
You may accedd to loop datas with @index @Arrayindex and @Length
{{@index}} / {{@Length}}
will output
1 / 12
2 / 12
3 / 12
...
@Arrayindex start at 0 instead of 1

Maybe there is a better way to do this, but something is really missing on this point

when using block {{#anArray}} {{/anArray}}
You may accedd to loop datas with @index @Arrayindex and @Length
{{@index}} / {{@Length}}
will output
1 / 12
2 / 12
3 / 12
...
@Arrayindex start at 0 instead of 1
@jrmax

jrmax commented Feb 10, 2014

Copy link
Copy Markdown

+1
this would be great!

@rcampbel

Copy link
Copy Markdown

This looks like LOGIC
-1

@dgmike

dgmike commented Mar 17, 2014

Copy link
Copy Markdown

Nice 👍

@dasilvacontin

Copy link
Copy Markdown
Collaborator

Maybe a helper function/plugin.

@dgmike

dgmike commented Dec 22, 2014

Copy link
Copy Markdown

Is there in spec?

@Arrayindex

Copy link
Copy Markdown

I am @Arrayindex

@rcampbel

rcampbel commented Nov 1, 2017

Copy link
Copy Markdown

So, just out of curiosity, this branch only handles when the value is an object.

  • Are there going to be unit tests that go along with this change?
  • What would the side effects be when the value is truthy/falsy??

Example
Data :

{
  "booleanValue": true,    // true
  "stringValue": "Some String",    // true
  "emptyString": "",    // false
  "whiteSpace": "    ",    // true
  "numericFalseValue": 0,    // false
  "numericTrueValue": 1    // true
}

Template:

{{#booleanValue}} {{@index}} / {{@length}} {{/booleanValue}}
{{#stringValue}} {{@index}} / {{@length}} {{/stringValue}}
{{#emptyString}} {{@index}} / {{@length}} {{/emptyString}}
{{#whiteSpace}} {{@index}} / {{@length}} {{/whiteSpace}}
{{#numericFalseValue}} {{@index}} / {{@length}} {{/numericFalseValue}}
{{#numericTrueValue}} {{@index}} / {{@length}} {{/numericTrueValue}}
  • How would this work with nested data??

Example
Data :

{
  employees : [
    {
      hasLeftCompany : false,
      firstName: "John"
    },
    {
      hasLeftCompany : true,
      firstName: "Jane"
    }
  ]
}

Template:

<table>
  <thead>
    <tr>
      <th colspan="2">Active Employees</th>
    </tr>
    <tr>
      <th></th>
      <th>First Name</th>
    </tr>
  </thead>
  <tbody>
    {{#employees}}
      {{^hasLeftCompany}}
        <tr>
          <td>{{@index}}</td>
          <td>{{fisrtName}}</td>
        </tr>
      {{/hasLeftCompany}}
    {{/employees}}  
  </tbody>
</table>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants