0

I am new to KnockOutJS. I am trying to use online sample, it works just fine and shows the expected results, if I don’t call the following script from html. But I need to use this script to display esri map on the browser later. If I uncomment the below script it will not work. I would appreciate if someone help me solve my problem.

<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?   v=3.0"/> 

Here is My Code

<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Imagery</title>
<link rel="stylesheet" type="text/css"     href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.0/js/dojo/dijit/themes/claro/claro.c     ss">
 <style type="text/css">
  html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
  #map{padding:0;}
</style>
</head>
<body>
<p data-bind="text: firstName"></p>
<p data-bind="text: lastName"></p>

<input type="text" data-bind="value: firstName" />
<input type="text" data-bind="value: lastName" />
<ul data-bind="foreach: items">
    <li><span data-bind="text:firstName"></span></li>
    <li><span data-bind="text:lastName"></span></li>
</ul>
  <ul data-bind="foreach: items">
    <li data-bind="text:name()"></li>

</ul>
</body>
 <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?     v=3.0"></script> <!--if I comment this line, it works-->
<script type="text/javascript" src="Scripts/knockout-2.1.0.js"></script>
<script type="text/javascript">
   var MyViewModel = function () {
       var self = this;

       self.firstName = ko.observable("Sravan");
       self.lastName = ko.observable("Kumar");

       self.items = ko.observableArray([
           { firstName: "A", lastName: "B", name: ko.computed = function () { return "Hello"; }},
           { firstName: "AA", lastName: "BB", name: ko.computed = function () { return "World"; } }
       ])
    };
   var viewModel = new MyViewModel();
   ko.applyBindings(viewModel);
 </script>

</html>
Sravan
  • 65
  • 1
  • 7
  • KO binding works: check [fiddle](http://jsfiddle.net/fedosov/3pry4/). Is there any error messages in browser debug console? – fedosov Jul 13 '12 at 07:52

1 Answers1

1

Your code works if you revert the order of inclusion of the scripts:

<script type="text/javascript" src="Scripts/knockout-2.1.0.js"></script>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?     v=3.0"></script> <!--if I comment this line, it works-->

Problem is that the esri script throws an XMLHttpRequestException error which causes a problem on the rest of the page.

Now you revert the order, ko bindings will work, but Chrome will continue to throw XMLHttpRequestException. Can the problem be: you are running the code from your file system rather than a local web server :

http://forums.arcgis.com/threads/61584-Sample-scripts-no-longer-work-since-upgrade-to-v3.0-of-the-API

nilgun
  • 10,460
  • 4
  • 46
  • 57