有一个模型,我想通过这样做来记录连接的设备类型:
var connections = DataLayer.context.ConnectionSet.filter(function(item) {
return item.Id == id;
}, {id: 1});
connections.forEach(function(item) {
console.log(item.Sender.Device.DeviceType);
});
item.Sender.Device.DeviceType
导致此错误:Uncaught RangeError: Maximum call stack size exceeded
这是我的型号:
$data.Entity.extend('SubliminalData.Connection', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'Sender': { 'type':'SubliminalData.DevicePort','required':true },
'Receiver': { 'type':'SubliminalData.DevicePort','required':true }
});
$data.Entity.extend('SubliminalData.Device', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'DeviceType': { 'type':'Edm.String','nullable':false,'required':true }
});
$data.Entity.extend('SubliminalData.Port', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true }
});
$data.Entity.extend('SubliminalData.DevicePort', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'Device': { 'type':'SubliminalData.Device','required':true },
'Port': { 'type':'SubliminalData.Port','required':true }
});
为什么这会给我一个最大调用异常,我该如何修复它?我找不到。
--更新--
我最近一直在努力让它发挥作用,我已经改变了我的模型,这样我就有了向后导航的属性。这现在更有意义了,但现在我有另一个问题。
新型号:
$data.Entity.extend('SubliminalData.Connection', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'Sender': { 'type':'SubliminalData.DevicePort','required':true,'inverseProperty':'SendingConnections' },
'Receiver': { 'type':'SubliminalData.DevicePort','required':true,'inverseProperty':'ReceivingConnections' }
});
$data.Entity.extend('SubliminalData.Device', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'DeviceType': { 'type':'Edm.String','nullable':false,'required':true },
'DevicePorts': { 'type':'Array','elementType':'SubliminalData.DevicePort','inverseProperty':'Device' }
});
$data.Entity.extend('SubliminalData.Port', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'PortType': { 'type':'Edm.String','nullable':false,'required':true },
'DevicePorts': { 'type':'Array','elementType':'SubliminalData.DevicePort','inverseProperty':'Port' }
});
$data.Entity.extend('SubliminalData.DevicePort', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'Device': { 'type':'SubliminalData.Device','required':true,'inverseProperty':'DevicePorts' },
'Port': { 'type':'SubliminalData.Port','required':true,'inverseProperty':'DevicePorts' },
'SendingConnections': { 'type':'Array','elementType':'SubliminalData.Connection','inverseProperty':'Sender' },
'ReceivingConnections': { 'type':'Array','elementType':'SubliminalData.Connection','inverseProperty':'Receiver' }
});
$data.EntityContext.extend('DataLayer.SubliminalDataContainer', {
'ConnectionSet': { type: $data.EntitySet, elementType: SubliminalData.Connection },
'DeviceSet': { type: $data.EntitySet, elementType: SubliminalData.Device },
'PortSet': { type: $data.EntitySet, elementType: SubliminalData.Port },
'DevicePortSet': { type: $data.EntitySet, elementType: SubliminalData.DevicePort }
});
$data.generatedContexts = $data.generatedContexts || [];
$data.generatedContexts.push(DataLayer.SubliminalDataContainer);
/*Context Instance*/
DataLayer.context = new DataLayer.SubliminalDataContainer( { name:'oData', oDataServiceHost: 'http://localhost:57703/WcfDataService1.svc' });
我的新问题是:
var connections = DataLayer.context.ConnectionSet.filter(function(item) {
return item.Id == id;
}, {id: 1});
connections.forEach(function(item) {
l(item); //works great!
l(item.Sender); //undefined :[
});
为什么我的发件人未定义?我以为我理解JayData,但我相信我不理解。
您的代码看起来不错,我们认为您从代码的其他部分得到了这个错误,很可能来自递归函数调用。你能用你的代码创建一个jsfiddle吗?这样我们就可以测试它了?