2016-05-16 120 views
0

使用寧靜node.js服務器和發送包裹在一個實體對象(查找)中的實體的集合一切正常,但集合中的實體被視爲普通對象而不是實體由微風。有沒有辦法解決這個問題,而不是使用一個實體的查找是否有可能使用複雜的對象,因爲它僅僅作爲一個持有者而已,僅此而已。感謝您的幫助微風得到一個不是對象的實體集合

來自服務器的響應是在使用此查詢格式

[ 
    oranges:[{id:1, name:'juicy'}, {id:2, name:'no seeds'}], 
    apples:[{id:1, name:'red'}, {id:2, name:'green'}] 
] 

breeze.EntityQuery.from('users/lookups') 
      .using(this.manager).execute() 
      .then(this.querySucceeded) 
      .catch(this.queryFailed); 

下面是查找

var entityType = { 
    name: this.entityNames.Lookup, 
    defaultResourceName: 'users/lookups', 
    autoGeneratedKeyType: breeze.AutoGeneratedKeyType.Identity, 
    dataProperties: { 
     lookupID: {dataType: DT.Int32, isPartOfKey: true} 
    }, 
    navigationProperties: { 
     apples: { 
      entityTypeName: this.entityNames.Apple 
     }, 
     orange: { 
      entityTypeName: this.entityNames.Orange 
     } 
    } 
}; 

元數據代碼Orange和Apple的meta

var entityType = { 
    name: this.entityNames.Apple, 
    defaultResourceName: 'users/lookups/Apples', 
    dataProperties: { 
     id: {type: DT.Int32}, 
     image: {type: DT.String}, 
     name: { complexTypeName: 'Translation:#model', isNullable: false} 
    } 
}; 


var entityType = { 
    name: this.entityNames.Orange, 
    defaultResourceName: 'users/lookups/Oranges', 
    dataProperties: { 
     id: {type: DT.Int32}, 
     image: {type: DT.String}, 
     name: { complexTypeName: 'Translation:#model', isNullable: false} 
    } 
}; 

的複合型翻譯

​​3210

回答

1

您的蘋果和桔子應該在響應數據識別的類型的服務器響應元。它們可以被認爲是實體這樣,他們分別是:

[ 
    oranges:[ 
    {$type:model.Orange, id:1, name:'juicy'}, 
    {$type:model.Orange, id:2, name:'no seeds'} 
    ], 
    apples:[ 
    {$type:model.Apple, id:1, name:'red'}, 
    {$type:model.Apple, id:2, name:'green'} 
    ] 
] 

你可以看到更多關於lookups in the Breeze documentation

+0

的$ type屬性做的工作很神奇,那會採取我的年齡感謝。關於Lookup Entity,我可以將其更改爲複雜類型,還是需要成爲Entity才能使用。再次感謝您 – ramon22

+0

您根本不需要查找實體。只需發回響應,Breeze就會將響應中的任何實體放入緩存中。 Breeze不會緩存外部對象,如果它不是實體。 –

相關問題