Skip to content

Instantly share code, notes, and snippets.

@odoe
Created June 23, 2011 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odoe/1043313 to your computer and use it in GitHub Desktop.
Save odoe/1043313 to your computer and use it in GitHub Desktop.
knockout.js to HTML binding example
<div id="osmcopy">
<a targer="_blank" data-bind="attr: {href: osmCopyURL}">
<span>OpenStreetMap</span></a>, contributors,
<a targer="_blank" data-bind="attr: {href: osmCCURL}">
<span>CC-BY-SA</span></a>
</div>
<div id="info">
<span data-bind="text: mapinfo">Extent</span>
<p/>
<ul id="details">
<li><strong>Field Name: </strong><a targer="_blank" data-bind="attr: {href: '#'}, click: search">
<span data-bind="text: oildetails()[0]"></span></a></li>
<li><strong>Gas?: </strong><span data-bind="text: oildetails()[1]"></span></li>
<li><strong>Oil?: </strong><span data-bind="text: oildetails()[2]"></span></li>
</ul>
</div>
var viewModel = {
mapinfo: ko.observable(),
oildetails: ko.observableArray([]),
osmCopyURL: ko.observable(),
osmCCURL: ko.observable(),
search: function() {
// just a demonstration of using a function in view model
var url = "http://www.google.com/search?as_q=" + this.oildetails()[0] +"+oil+field+kansas";
var newwindow = window.open(url, 'name');
if (window.focus) { newwindow.focus(); }
}
}
@akira-maruf
Copy link

Thanks

@9560026742ravi
Copy link

I tried your code in my chrome browser but not running according to your above scenario.
output :

OpenStreetMap, contributors, CC-BY-SA
Extent
Field Name:
Gas?:
Oil?:

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment