我检索表单中的元数据:
{"version":"1.0","dataServices":{"dataServiceVersion":"1.0","schema":[{"namespace":"IdeasDbModel","entityType":[{"name":"Category","key":{"propertyRef":[{"name":"CategoryID"}]},"property":[{"name":"CategoryID","type":"Edm.Int32","nullable":"false","extensions":[{" ...
如何在JavaScript中解析此问题以检索元数据信息,例如列类型,主键等,例如表类别具有主键(propertyRef)CategoryID,该列的类型是Edm.Int32?我不明白结果的格式。在dataServices下 - > Schema [0] - > entityType(或association),它只是一个对象数组,所以我必须循环遍历每个元素才能找到匹配的结果,还是有更简单的方法让列按名称键入?
答案 0 :(得分:1)
你应该看看JayData。它从元数据创建JavaScript类上下文,您可以更直观地使用它。在您的页面中引用JayData之后的示例:
$data.service("http://localhost:60349/Northwind.svc", function (f, t) {
var northwind = f();
console.dir(northwind["Categories"].elementType.memberDefinitions["$Category_ID"]);
});
结果:
computed: true
configurable: true
dataType: "Edm.Int32"
definedBy: function Category(){
enumerable: true
key: true
kind: "property"
name: "Category_ID"
nullable: false
type: "Edm.Int32"