4

多対多の関連付けを作成したいときに、いくつかの問題に直面します。わからないから。私はこのように関係を築こうとしています。しかし、私にはわかりません。誰かが私を助けることができますか?どうすればいいですか?これが私のコードです

Ext.define('Ext4Example.model.Category', {
extend    : 'Ext.data.Model',
alias     : 'widget.categoryModel',
idProperty: 'id',    
fields: [
    {name:'id',              mapping:'id',                type:'int'},
    {name:'name',            mapping:'name',              type:'string'}
],
proxy: {
    type: 'ajax',
    noCache: false,
    api: {
        create  : '${createLink(controller:'category', action: 'create')}',
        read    : '${createLink(controller:'category', action: 'read')}',
        update  : '${createLink(controller:'category', action: 'update')}',
        destroy : '${createLink(controller:'category', action: 'destroy')}'
    },
    actionMethods: {
        create  : 'POST',
        read    : 'GET',
        update  : 'PUT',
        destroy : 'DELETE'            
    },        
    reader: {
        type    : 'json',
        root    : 'data',
        totalProperty   : 'total',
        successProperty : 'success',
        messageProperty : 'message',
        implicitIncludes: true
    },
    writer: {
      type      : 'json',
      root      : 'data',
      writeAllFields: true 
    },
    simpleSortMode: true
},
hasMany: [{model: 'Manufacturer', name: 'manufacturers'}]

});

2番目のモデルはこちら

Ext.define('Ext4Example.model.Manufacturer', {
extend    : 'Ext.data.Model',
alias     : 'widget.manufacturerModel',
idProperty: 'id',    
fields: [
    {name:'id',              mapping:'id',                type:'int'},
    {name:'name',            mapping:'name',              type:'string'}
],
proxy: {
    type: 'ajax',
    noCache: false,
    api: {
        create  : '${createLink(controller:'manufacturer', action: 'create')}',
        read    : '${createLink(controller:'manufacturer', action: 'read')}',
        update  : '${createLink(controller:'manufacturer', action: 'update')}',
        destroy : '${createLink(controller:'manufacturer', action: 'destroy')}'
    },
    actionMethods: {
        create  : 'POST',
        read    : 'GET',
        update  : 'PUT',
        destroy : 'DELETE'            
    },        
    reader: {
        type    : 'json',
        root    : 'data',
        totalProperty   : 'total',
        successProperty : 'success',
        messageProperty : 'message',
        implicitIncludes: true
    },
    writer: {
      type      : 'json',
      root      : 'data',
      writeAllFields: true 
    },
    simpleSortMode: true
},
hasMany: [{model: 'Category', name: 'categories'}]

});

4

1 に答える 1

2

まず、何が機能していないのか説明してください。hasMany関係によって作成された魔法のメソッドはモデルで利用できませんか?マジックメソッドを呼び出すとデータが読み込まれませんか?発生している問題についてさらに説明してください。

おそらく、このブログ投稿は役に立ちますか? http://extjs-tutorials.blogspot.com/2012/05/extjs-hasmany-relationships-rules.html

ブログ投稿からのいくつかの重要なヒント(リンクがある時点で死んだ場合)

  1. *しない非常に正当な理由がない限り、プロキシは常にストアではなくモデルに配置してください。
  2. hasManyの関係で使用する場合は、常に子モデルを要求してください。****
  3. 子を自由にロードしたい場合は、常にforeignKeyを使用してください
  4. 親と同じ応答で子を返す場合は、常にassociationKeyを使用してください
  5. 必要に応じて、foreignKeyとassociationKeyの両方を使用できます
  6. 常にhasManyの関係に名前を付けます
  7. hasMany関係では、常に完全修飾モデル名を使用してください
  8. リーダーのルートに意味のある名前(「データ」以外)を付けることを検討してください
  9. 子モデルは、hasManyが機能するためにbelongsTo関係を必要としません

*ストアはモデルのプロキシを継承し、いつでもオーバーライドできます

**簡単にし、潜在的な循環参照を回避するために、app.jsでそれらを要求できます

クレジット:Neil McGuigan(http://www.blogger.com/profile/14122981831780837323)

于 2012-12-15T17:58:05.283 に答える