DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
    • can-construct-super
    • can-define-stream
    • can-fixture
    • can-fixture-socket
    • can-jquery
    • can-stache-converters
      • Pages
        • select[multiple]
        • input[type=checkbox]
        • input[type=radio]
        • select
      • Converters
        • boolean-to-inList
        • either-or
        • equal
        • index-to-selected
        • not
        • string-to-any
    • can-stream
    • can-vdom
    • can-view-import
    • can-zone
    • steal-stache
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Ecosystem
  • /
  • can-stache-converters
  • /
  • index-to-selected
  • / On this page
    • index-to-selected

      function

      A converter that binds to a <select> value in order to two-way bind a selected item from a list using the index as the key.

      • source

      index-to-selected(~item, list)

      When the getter is called, returns the index of the passed in item (which should be a can-compute from the provided list.

      When the setter is called, takes the selected index value and finds the item from the list with that index and passes that to set the compute's value.

      <select {($value)}="index-to-selected(~person, people)">
      
          {{#each people}}
      
              <option value="{{%index}}">{{name}}</option>
      
          {{/each}}
      
      </select>
      

      Parameters

      1. item {can-compute}:

        A compute whose item is in the list.

      2. list {can-define/list/list|can-list|Array}:

        A list used to find the item.

      Returns

      {can-compute}:

      A compute that will be two-way bound to the select's value.

      Use

      This will most often be used in conjunction with a <select> element and a bunch of options.

      The provided item must be a can-compute so that its value can be set when the user selects own of the dropdown options.

      You must use the indexes from the list as your <option> values. This is how it looks up items in the list both in the getter and the setter.

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