0

我是 KnockOutJS 的新手。我正在尝试使用在线示例,如果我不从 html 调用以下脚本,它可以正常工作并显示预期结果。但是我需要使用这个脚本稍后在浏览器上显示 esri 地图。如果我取消注释以下脚本,它将不起作用。如果有人帮助我解决我的问题,我将不胜感激。

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

这是我的代码

<!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>
4

1 回答 1

1

如果您恢复包含脚本的顺序,您的代码将起作用:

<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-->

问题是 esri 脚本会引发 XMLHttpRequestException 错误,这会导致页面的其余部分出现问题。

现在您恢复顺序,ko 绑定将起作用,但 Chrome 将继续抛出 XMLHttpRequestException。问题可能是:您正在从文件系统而不是本地 Web 服务器运行代码:

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

于 2012-07-14T09:11:11.950 回答