Knockoutjs sets the current item.

In this code: http://jsfiddle.net/PDwBF/1/
the google link does not work. How to restore it?

<ul data-bind="foreach: Items">
    <li data-bind="click: $root.SetCurrent">
        <p data-bind="text: id"></p>
        <div>
            <a href="http://google.com" target="_blank">Go to google</a>
        </div>    
    </li>
</ul>    

function ViewModel() 
{ 
  var self = this;
  self.SelectedItem = ko.observable();
  self.Items = ko.observableArray([]);
  self.SetCurrent = function(item) 
  {
      self.SelectedItem(item);
  };
};  

var vm = new ViewModel();
ko.applyBindings(vm); 

vm.Items.push({id: 55});
vm.Items.push({id: 66});
vm.Items.push({id: 77});
+3
source share
2 answers

One option is to return true; from your SetCurrent method, which will enable the default action: http://jsfiddle.net/rniemeyer/PDwBF/3/

Thanks rpn https://groups.google.com/group/knockoutjs/browse_thread/thread/6ef1081249377728

+2
source

If you add return true, it works.

eg.

function ViewModel() 
{ 
  var self = this;
  self.SelectedItem = ko.observable();
  self.Items = ko.observableArray([]);
  self.SetCurrent = function(item) 
  {
      self.SelectedItem(item);
      return true;
  };
};
0
source

All Articles