Created
June 23, 2011 19:00
-
-
Save odoe/1043313 to your computer and use it in GitHub Desktop.
knockout.js to HTML binding example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); } | |
} | |
} |
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
Thanks