编辑:在这里查看 Steven 的博客文章以及示例下载代码:http: //blog.stevensanderson.com/2012/03/06/single-page-application-packages-and-samples/
也不知道如何访问助手,很想知道所以我可以玩它:-)
现在这似乎可以解决问题:
<script src="../../Scripts/knockout-2.0.0.js" type="text/javascript"></script>
<script src="../../Scripts/upshot.js" type="text/javascript"></script>
<script src="../../Scripts/upshot.compat.knockout.js" type="text/javascript"></script>
<script type="text/javascript">
upshot.metadata({ "CLASSNAME:#NAMESPACE":{ "key": ["aId"],
"fields": {
"aId": { "type": "Int32:#System" },
"Title": { "type": "String:#System" },
"Description": { "type": "String:#System" },
"Effort": { "type": "Double:#System" }
}
}
});
var myDataSource = new upshot.RemoteDataSource({
providerParameters: {
url: "http://localhost:7018/api/CONTROLLERNAME",
operationName: "",
operationParameters: {}
},
entityType: "CLASSNAME:#NAMESPACE"
});
myDataSource.refresh(function (results) {
alert(results[0].Title());
});
</script>
您需要将 CLASSNAME:#NAMESPACE 替换为您的类名和命名空间,例如:“WorkItem:#MySystem.Models”。
并将 CONTROLLERNAME 替换为控制器的实际名称,在这种情况下
public class MyTasksController : ApiController
您需要将 CONTROLLERNAME 替换为 MyTasks
并根据您的模型对象填充元数据中的内容。我希望代码示例很快上线,因为这是很多工作:-(