有一个模型,我希望能够通过执行以下操作记录连接的设备类型:
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,但我相信我不了解。