Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knockoutjs setting current item

In this code: http://jsfiddle.net/PDwBF/1/
link to google doesn't work. How to repair 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});
like image 998
Lari13 Avatar asked Feb 25 '26 03:02

Lari13


1 Answers

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

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

like image 186
Lari13 Avatar answered Feb 27 '26 21:02

Lari13



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!