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
  • /
  • boolean-to-inList
  • / On this page
    • boolean-to-inList

      function

      A converter that binds a boolean attribute, such as an <input> value to whether or not an item is in a list.

      • source

      boolean-to-inList(item, list)

      When the getter is called, returns true if item is within the list, determined using .indexOf.

      When the setter is called, if the new value is truthy then the item will be added to the list using .push; if it is falsey the item will removed from the list using .splice.

      <input type="checkbox" {($value)}="boolean-to-inList(item, list)" />
      

      Parameters

      1. item {*}:

        The item to which to check

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

        The list

      Returns

      {can-compute}:

      A compute that will be used by can-stache-bindings as a getter/setter when the element's value changes.

      Use

      Use this converter when two-way binding to an element with a boolean attribute, such as a checkbox.

      var map = new DefineMap({
          item: 5,
          list: [1, 2, 3, 4, 5]
      });
      
      var template = stache('<input type="checkbox" {($value)}="boolean-to-inList(item, list)" />');
      
      document.body.appendChild(template(map));
      
      var input = document.querySelector('input[type=checkbox]');
      
      console.log(input.checked); // -> true
      
      map.item = 6;
      
      console.log(input.checked); // -> false
      
      map.list.push(6);
      
      console.log(input.checked); // -> true
      

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