title: Expand one element and collapse all other element in knockout js
body: <p>In knockout is it possible to collapse all other opened row and expand only clicked row.</p>
  
  <p>I am referring this <a href="http://jsfiddle.net/XAzW6/34/" rel="nofollow">Fiddle example</a> for it.</p>
  
  <p><strong>view -</strong> </p>
  
  <pre><code>&lt;ul data-bind="foreach: items"&gt; &lt;a href="#" data-bind="click: toggle, text:linkLabel"&gt;&lt;/a&gt; 
      &lt;button data-bind="text:name"&gt;&lt;/button&gt;
      &lt;div data-bind="visible:expanded"&gt;
          &lt;input data-bind="value:name"&gt;&lt;/input&gt;
      &lt;/div&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p><strong>viewModel -</strong></p>
  
  <pre><code>function Sample(item) {
      var self = this;
      self.name = ko.observable(item.name);
      self.id = ko.observable(item.id);
      self.expanded = ko.observable(false);
      self.toggle = function (item) {
          self.expanded(!self.expanded());
      };
      self.linkLabel = ko.computed(function () {
          return self.expanded() ? "collapse" : "expand";
      }, self);
  }
  
  var viewModel = function () {
      var self = this;
  
      var json = [{
          "name": "bruce",
          "id": 1
      }, {
          "name": "greg",
          "id": 2
      }]
  
      var data = ko.utils.arrayMap(json, function (item) {
          return new Sample(item); // making things independent here 
      });
      self.items = ko.observableArray(data);
  };
  
  ko.applyBindings(new viewModel());
  </code></pre>
  
  <p>Here its not collapsing already opened row. I tried to fetch complete items in toggle function but it did not work.</p>
  
  <p>I am new to knock out. please suggest.</p>
  
  <p>Update -</p>
  
  <p>I tried this code to make first one extended by default -</p>
  
  <pre><code>var index=0;
  var data = ko.utils.arrayMap(json, function(item) {
        if(index++===0){
        return new Sample(item,true);
      }else{
          return new Sample(item,false);
      }
    });
  </code></pre>
  
  <p>But above given code is not working as expected.</p>