我已经使用了一个Wijmo数据(带有wijgrid)样本(breeze-native.html)来处理Angular。它确实很好。 但是,当我尝试调整它以运行我的数据时,我得到了可怕的'RangeError:超出最大调用堆栈大小'错误。由于我的数据不是“微风标准”,我使用了JsonResultsAdapter和我自己的元数据来创建实体。这对Angular来说没问题,但不喜欢wijmo。
Northwind示例中的数据如下所示: [{“Product_ID”:1,“Supplier_ID”:1,“Category_ID”:1,“Product_Name”:“Chai”,“English_Name”:“Dharamsala Tea”,“Quantity_Per_Unit”:“10 box x 20 bags”,“ UNIT_PRICE “:18.0,” Units_In_Stock “:39,” Units_On_Order “:0”,Reorder_Level “:10,” 停产“:假},{...}]
我的数据是这样的: [{ “ID”: “1”, “ID用户所”: “1”, “idOrganisation”: “2”, “isActive”: “1”, “idRole”: “1”, “SubOrganisations”: “1”, “strEMail”: “bob@gmail.com”, “strTel”:空, “strUserName中”: “鲍勃”, “strPassword”: “* 196BDEDE2AE4F84CA44C47D54D78478C7E2BD7B7”, “datCreated”:空, “datLastModified”:空, “idUserLastModified” :NULL, “idUserCreated”:空},{...}]
由于没有真正的区别,问题必须在于元数据或JsonResultsAdapter。
这里是带有JsonResultsAdapter的模块:
angular.module('app_jsonResultsAdapter',['app_metadata'])
/* jsonResultsAdapter: parses data into entities */
.value('bem_jsonResultsAdapter',
new breeze.JsonResultsAdapter({
name: "seltec",
extractResults: function(json) {
return json.results;
},
visitNode: function(node, mappingContext, nodeContext) {
var entityType = "Users";
var propertyName = nodeContext.propertyName;
var ignore = propertyName && propertyName.substr(0, 1) === "$";
return {
entityType: entityType,
nodeId: node.$id,
nodeRefId: node.$ref,
ignore: ignore
};
}
}));
这是包含元数据的模块:
angular.module('app_metadata', ['logger'])
.factory("bem_metadata", function () {
var bem_Metadata = {
getUserMetadata: getUserMetadata
};
return bem_Metadata;
function getUserMetadata(){
var x = {
"metadataVersion": "1.0.4",
// "namingConvention": "camelCase",
"localQueryComparisonOptions": "caseInsensitiveSQL",
"structuralTypes": [
{
"shortName": "Users",
"namespace": "Models.Seltec-T_Users",
"autoGeneratedKeyType": "None",
"defaultResourceName": "Users",
"dataProperties": [
// `ID` varchar(38) NOT NULL,
{
"name": "ID",
"dataType": "String",
"isPartOfKey": true,
"validators": [
{
"name": "string"
}
]
},
// `idUser` varchar(38) DEFAULT NULL,
{
"name": "idUser",
"dataType": "String",
"validators": [
{
"name": "string"
}
]
},
// `idOrganisation` int(11) DEFAULT NULL,
{
"name": "idOrganisation",
"dataType": "Int32",
"validators": [
{
"name": "int32"
}
]
},
// `isActive` tinyint(1) DEFAULT '0',
{
"name": "isActive",
"dataType": "Boolean",
"validators": [
{
"name": "bool"
}
]
},
// `idRole` int(11) DEFAULT '0',
{
"name": "idRole",
"dataType": "Int32",
"validators": [
{
"name": "int32"
}
]
},
// `SubOrganisations` tinyint(1) DEFAULT '0',
{
"name": "SubOrganisations",
"dataType": "Boolean",
"validators": [
{
"name": "bool"
}
]
},
// `strEMail` varchar(100) DEFAULT NULL,
{
"name": "strEMail",
"dataType": "String",
"validators": [
{
"name": "string"
}
]
},
// `strTel` varchar(30) DEFAULT NULL,
{
"name": "strTel",
"dataType": "String",
"validators": [
{
"name": "string"
}
]
},
// `strUsername` varchar(255) DEFAULT NULL,
{
"name": "strUsername",
"dataType": "String",
"validators": [
{
"name": "string"
}
]
},
// `strPassword` varchar(255) DEFAULT NULL,
{
"name": "strPassword",
"dataType": "String",
"validators": [
{
"name": "string"
}
]
},
// `datCreated` datetime DEFAULT NULL,
{
"name": "datCreated",
"dataType": "DateTime",
"validators": [
{
"name": "date"
}
]
},
// `datLastModified` datetime DEFAULT NULL,
{
"name": "ID",
"dataType": "DateTime",
"validators": [
{
"name": "date"
}
]
},
// `idUserLastModified` varchar(38) DEFAULT NULL,
{
"name": "idUserLastModified",
"dataType": "String",
"validators": [
{
"name": "string"
}
]
},
// `idUserCreated` varchar(38) DEFAULT NULL,
{
"name": "idUserCreated",
"dataType": "String",
"validators": [
{
"name": "string"
}
]
}
]
}
],
"resourceEntityTypeMap": {
"User": "User"
}
}
return x;
}
});
控制器:
angular.module('app',['app_metadata', 'wijmo'])
.controller('Ctrl', function ($scope, bem_metadata){
breeze.config.initializeAdapterInstance("modelLibrary", "backingStore", true);
var j = new breeze.JsonResultsAdapter({
name: "seltec",
extractResults: function(json) {
return json.results;
},
visitNode: function(node, mappingContext, nodeContext) {
var entityType = "Users";
var propertyName = nodeContext.propertyName;
var ignore = propertyName && propertyName.substr(0, 1) === "$";
return {
entityType: entityType,
nodeId: node.$id,
nodeRefId: node.$ref,
ignore: ignore
};
}
});
var dataService = new breeze.DataService({
serviceName: "http://lanet.local/backend/webservice/public/rest/index.php/",
hasServerMetadata: false,
jsonResultsAdapter: j
});
var ms = new breeze.MetadataStore();
var x = bem_metadata.getUserMetadata();
ms.importMetadata (x)
var manager = new breeze.EntityManager({
dataService: dataService,
metadataStore: ms
});
$scope.users = [];
var query = new breeze.EntityQuery("users");
manager.executeQuery(query).then(function (data) {
$scope.users = data.results;
$scope.$digest();
}).fail(function (e) {
alert(e);
});
});
我在html中的所有内容都是网格:
<wijgrid id="dataGrid" data="{{users}}" allowEditing="true" allowSorting="true" columnsAutogenerationMode="none"
style="width: 600px;">
<columns>
<column headerText="Username" dataKey="strUsername"></column>
<column headerText="Email" dataKey="strEMail"></column>
</columns>
</wijgrid>
我想知道的是,为什么我的元数据会导致wijgrid出现这样的问题。它适用于来自Web API的数据,所以我知道它应该工作!!
的Ta! 克雷格
PS:我想如果我添加Northwind示例会有所帮助:
<!DOCTYPE html>
<html lang="en" ng-app="wijmo">
<head>
<title>Data - BreezeJs without BreezeDataView</title>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="description" content="Remote shaped data downloaded by BreezeJs shown in a wijgrid"/>
<meta name="keywords" content=""/>
<meta name="author" content="ComponentOne"/>
<!--jQuery References-->
<script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.min.js" type="text/javascript"></script>
<!--Theme-->
<link href="http://cdn.wijmo.com/themes/aristo/jquery-wijmo.css" rel="stylesheet" type="text/css"/>
<!--Wijmo Widgets CSS-->
<link href="http://cdn.wijmo.com/jquery.wijmo-pro.all.3.20131.3.min.css" rel="stylesheet" type="text/css"/>
<!--Wijmo Widgets JavaScript-->
<script src="http://cdn.wijmo.com/jquery.wijmo-open.all.3.20131.3.js" type="text/javascript"></script>
<script src="http://cdn.wijmo.com/jquery.wijmo-pro.all.3.20131.3.js" type="text/javascript"></script>
<!--<script src="http://cdn.wijmo.com/wijmo/wijmo.data.breeze.js" type="text/javascript"></script>-->
<script type="text/javascript" src="Scripts/wijmo.data.breeze.js"></script>
<!--Breeze.js References -->
<script type="text/javascript" src="Scripts/q.js"></script>
<script type="text/javascript" src="Scripts/breeze.debug.js"></script>
<script type="text/javascript" src="Scripts/datajs-1.0.3.js"></script>
<script type="text/javascript" src="Scripts/toastr.min.js"></script>
<script src="Scripts/angular.js"></script>
<script src="http://cdn.wijmo.com/interop/angular.wijmo.3.20131.3.js" type="text/javascript"></script>
<style type="text/css">
table {
border-collapse: collapse;
}
table caption {
font-size: 150%;
}
th, td {
border: 1px solid #AAAAAA;
text-align: center;
padding: 0.5em;
}
th {
background-color: #CCCCCC;
}
</style>
<script id="scriptInit" type="text/javascript">
$.support.cors = true;
function ViewModel($scope) {
var dataService = new breeze.DataService({
serviceName: "http://demo.componentone.com/aspnet/NorthwindAPI/api/read",
hasServerMetadata: false
});
var ms = new breeze.MetadataStore();
var manager = new breeze.EntityManager({
dataService: dataService,
metadataStore: ms
});
$scope.products = [];
var query = new breeze.EntityQuery("Product");
manager.executeQuery(query).then(function (data) {
$scope.products = data.results;
$scope.$digest();
}).fail(function (e) {
alert(e);
});
}
</script>
</head>
<body class="demo-single" ng-controller="ViewModel">
<div class="container">
<div class="header">
<h2>Data - BreezeJs without BreezeDataView</h2>
</div>
<div class="main demo">
<h1>Products</h1>
<wijgrid id="dataGrid" data="{{products}}" allowEditing="true" allowSorting="true"
columnsAutogenerationMode="none"
style="width: 600px;">
<columns>
<column headerText="Product Name" dataKey="Product_Name"></column>
<column headerText="English Name" dataKey="English_Name"></column>
</columns>
</wijgrid>
</div>
</div>
</body>
</html>