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