These are chat archives for canjs/canjs

1st
Feb 2017
Nico R.
@nriesco
Feb 01 2017 05:36

this should be an easy one...
I'm trying to do some sort of "variable-variable" thing.

This code works but seems like a workaround:

{{#each headers}}
  <td>
    <input class="disabled no-form" {($value)}="{{varName}}">
  </td>
{{/each}}

(varName is name, lastName, and so on..)

what I really want to do is something like this, but of course it won't work:

{{#each headers}}
  <td>
    {{{{varName}}}}
  </td>
{{/each}}

I guess there is a simple way of doing this, maybe a modifier or special keyword.
thanks

p.s. I don’t want to edit the contents, just to show the value, the input part is covered and working
Gira Minus
@gKreator
Feb 01 2017 05:44
I tjink it is {{.}}
Nico R.
@nriesco
Feb 01 2017 06:18
I mean header is an array that contains an object, this object has a property called varName and I need to print whatever is in there like {{name}} only that the value name is name, lastName, etc..
Gira Minus
@gKreator
Feb 01 2017 06:40
{{Urobject.urname}}
Nico R.
@nriesco
Feb 01 2017 07:13
@gKreator no that won’t work
Gira Minus
@gKreator
Feb 01 2017 07:26
You want the key?
Sorry the way ur asking this is a bit confusing. Can you make a jsbin?
Jeroen Cornelissen
@jeroencornelissen
Feb 01 2017 07:58

@nriesco I think you want something like:

{{#each headers}}
  {{#each .}}
    <p>{{%index}} -- {{%key}} -- {{.}}</p>
  {{/each}}  
{{/each}}

http://jsbin.com/robafivefe/1/edit?html,js,output

Gira Minus
@gKreator
Feb 01 2017 07:59
That should cover all possibilities lol
Nico R.
@nriesco
Feb 01 2017 08:10
@gKreator yes, my question is no so clear
@jeroencornelissen that will print the keys and the values but I would like to print the value of the varible wich name is that key or value
Gira Minus
@gKreator
Feb 01 2017 08:11
Ohhh
You want to print from a second object?
Nico R.
@nriesco
Feb 01 2017 08:12
this works: <input class="disabled no-form" disabled="disabled" {($value)}="{{varName}}”>
that way the value is set in a “variable” way
I just thought there might be a simple way of doing something like {{{{varName}}}}
some sort of modifier
Gira Minus
@gKreator
Feb 01 2017 08:14
Use a helper function
Jeroen Cornelissen
@jeroencornelissen
Feb 01 2017 08:14
You could use a helper function where you pass the %key to
Gregg Roemhildt
@roemhildtg
Feb 01 2017 14:12

@nriesco you can do this:

        {{#each element as e}}
          <tr>
            {{#each headers}}
              <td>
                {{e[varName]}}
              </td>
            {{/each}}
          </tr>
        {{/each}}

http://jsbin.com/keyuniceqe/edit?html,js,output

This wasn't added till canjs 3 though so not sure if it'll work with your donejs app
Kevin Phillips
@phillipskevin
Feb 01 2017 14:36
yep, Bracket expressions are the way to do this without a helper: http://canjs.com/doc/can-stache/expressions/bracket.html
Justin Meyer
@justinbmeyer
Feb 01 2017 15:17
I'll be going through some thoughts on 3.0 later today: https://www.youtube.com/watch?v=eT78XxsvpQw