2011-12-26 2 views
1

モデルのコレクションとして1つのプロパティが必要なので、関連付けを試みましたが、 (ストア→レコード→データ→配列プロパティ) "[オブジェクトオブジェクト]"のようになっていますが、配列コレクションではありません。EXTJS-4では、ストア(ロードイベント)の配列コレクションとして関連データを取得しません。

Recordで「raw」プロパティを見ると、適切な配列コレクションが得られます。

すなわち

マイコード

Ext.define('MyApp.model.user.examModl', { 
    extend: 'Ext.data.Model',  
    idProperty :'examId', 
    hasMany: 'MyApp.model.user.examTypeModl',  
      proxy:{   
     type: 'ajax',  
     api: { 
       read: 'readExam.htm'   //url to read data from db 
      }, 
     reader: { 
      type: 'json', 
      root: 'res', 
      idProperty: 'examId', 
      successProperty: 'success', 
      totalProperty: 'totalCount' 
     }, 
     writer: { 
       type: 'json', 
       encode: true, 
       root: 'res', 
       writeAllFields : true 
      } 
    }, 
    fields:[{ 
        name: 'examId', 
        type: 'string' 
       }, 
       { 
        name: 'examName', 
        type: 'string' 
       }, 
      { 
        name: 'examTypes',//It shoud be in array 
        type: 'string'   // is there any collection type to be specified ? 
       }] , 
       associations: [ 
     {type: 'hasMany', model: 'MyApp.model.user.examTypeModl', name: 'examTypes'} 
    ] 
}); 

Ext.define('MyApp.model.user.examTypeModl', { 
    extend: 'Ext.data.Model',  
    idProperty :'examTypeId', 
    belongsTo: 'examTypes', 
    fields:[{ 
        name: 'examTypeId', 
        type: 'string' 
       }, 
       { 
        name: 'examId', 
        type: 'string' 
       },    
       { 
        name: 'examType', 
        type: 'string' 
       }, 

       { name: 'active', 
        type: 'bool' 

       }]  
}); 

私のJSON responceは次のようになります - 私の店のLoadイベントで

{"res":[{"examId":1,"examName":"mathematics","examTypes":[{"examTypeId":1,"examId":"1","examType":"MCQ","active":true}]}],"totalCount":1,"success":true} 

、私は "記録" パラメータを見て、

records[1].data.examTypes="[object Object]" 

as like object , but iam getting in raw property 

records[1].raw.examTypes = proper array collection. 

私はわかりません私は間違っているか、不足している/間違って割り当てられた財産があります。

答えて

1

フィールド定義に{ name: 'examTypes', type: 'auto' }を使用してください。 examTypesは記録されませんが、配列は変更されません。

+0

こんにちは、私は知っている、私はどのように私はexamtypeレコードとして得ることができる、リプレイのおかげで、ありがとう。もしあなたが知っていれば、plsは関連リンクを提供します。 – vineth

+0

こんにちはロロ、リプレイのおかげで、その有用なことがわかります、私はどのように私はexamtypeレコードとして得ることができます。もしあなたが知っていれば、plsは関連リンクを提供します。 – vineth

+0

APIにいくつかの情報があります。 'Ext.data.Field'と' Ext.data.Types'クラスの 'type'フィールドを検索します。アレイタイプはなく、自動であることが判明しました。おそらく配列はautoにデフォルト設定されています。カスタムタイプを追加することができます( 'Ext.data.Types' APIページの例を参照してください)。 – Krzysztof

関連する問題