DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
    • can-component
    • can-compute
    • can-connect
    • can-define
    • can-define/list/list
    • can-define/map/map
    • can-route
    • can-route-pushstate
    • can-set
    • can-stache
      • Pages
        • Magic Tag Types
        • Scope and Context
        • Expressions
        • Template Acquisition
        • Helpers
        • Live Binding
      • Methods
        • from
        • registerConverter
        • registerHelper
        • registerPartial
        • registerSimpleHelper
        • safeString
      • Tags
        • {{expression}}
        • {{{expression}}}
        • {{#expression}}
        • {{/expression}}
        • {{^expression}}
        • {{>key}}
        • {{!expression}}
        • {{else}}
      • Expressions
        • Bracket Expression
        • Call Expression
        • Hash Expression
        • Helper Expression
        • KeyLookup Expression
        • Literal Expression
      • Key Operators
        • @at
        • ~compute
        • ./current
        • ../parent
        • %special
        • this
        • *variable
        • key
      • Helpers
        • {{#if expression}}
        • {{#unless expression}}
        • {{#each expression}}
        • {{#with expression}}
        • {{log}}
        • {{#is expressions}}
        • {{#switch expression}}
        • {{#case expression}}
        • {{#default}}
        • {{joinBase expressions}}
      • Types
        • getterSetter
        • helper
        • helperOptions
        • renderer
        • sectionRenderer
        • simpleHelper
    • can-stache/helpers/route
    • can-stache-bindings
  • Ecosystem
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Core
  • /
  • can-stache
  • /
  • Bracket Expression
  • / On this page
    • Bracket Expression

      typedef
      • source

      [key]

      Evaluates key and looks up the result in the scope.

      {{[key]}}
      

      Parameters

      1. key {Literal Expression|KeyLookup Expression|Call Expression|Helper Expression}:

        A Literal, KeyLookup, Call, or Helper expression to evaluate and look up the result in the scope.

      CALL_EXPRESSION[key]

      Evaluates key and looks up the result in the return value of CALL_EXPRESSION.

      {{method()[key]}}
      

      Parameters

      1. CALL_EXPRESSION {Call Expression|Helper Expression|KeyLookup Expression}:

        A Call, Helper, or KeyLookup expression that may or may not return a value.

      2. key {Literal Expression|KeyLookup Expression|Call Expression|Helper Expression}:

        A Literal, KeyLookup, Call, or Helper expression to evaluate and look up the result in the result of CALL_EXPRESSION.

      Use

      A bracket expression can be used to look up a dynamic property in the scope. This looks like:

      Template:
          <h1>{{[key]}}</h1>
      
      Data:
          {
              key: "name",
              name: "Kevin"
          }
      
      Result:
          <h1>Kevin</h1>
      

      This can be useful for looking up values using keys containing non-alphabetic characters:

      Template:
          <h1>{{["person:name"]}}</h1>
      
      Data:
          {
              "person:name": "Kevin"
          }
      
      Result:
          <h1>Kevin</h1>
      

      Bracket expressions can also be used to look up a value in the result of another expression:

      Template:
      {{getPerson()[key]}}
      
      Data:
          {
              key: "name",
              getPerson: function() {
                  return {
                      name: "Kevin"
                  };
              }
          }
      
      Result:
          <h1>Kevin</h1>
      

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.