3

モデルの関連付けを介してネストされたXMLデータを書き込もうとしていますが、先に進むことができません。

まず第一に、XML:

<?xml version="1.0" encoding="utf-8"?>
<card>
    <generalData>
        <name>A card</name>
        <description>That's a description</description>
    </generalData>
    <specificData>
        <number>100</number>
        <type>int</type>
    </specificData>
    <otherStuff>
        <note>Those notes...</note>
    </otherStuff>
</card>

モデルのコードは次のとおりです。

Ext.define ('generalData', {
    extend: 'Ext.data.Model' ,
    fields: ['name', 'description']
});

Ext.define ('specificData', {
    extend: 'Ext.data.Model' ,
    fields: ['number', 'type']
});

Ext.define ('otherStuff', {
    extend: 'Ext.data.Model' ,
    fields: ['note']
});

Ext.define ('Card', {
    extend: 'Ext.data.Model' ,

    requires: ['generalData', 'specificData', 'otherStuff'] ,

    hasOne: [{
        name: 'generalData' ,
        model: 'generalData' ,
        getterName: 'getGeneralData' ,
        associationKey: 'generalData' ,
        reader: {
            type: 'xml' ,
            root: 'generalData' ,
            record: 'generalData'
        } ,
        writer: {
            type: 'xml' ,
            documentRoot: 'generalData' ,
            record: 'generalData'
        }
    } , {
        name: 'specificData' ,
        model: 'specificData' ,
        getterName: 'getSpecificData' ,
        associationKey: 'specificData' ,
        reader: {
            type: 'xml' ,
            root: 'specificData' ,
            record: 'specificData'
        } ,
        writer: {
            type: 'xml' ,
            documentRoot: 'specificData' ,
            record: 'specificData'
        }
    } , {
        name: 'otherStuff' ,
        model: 'otherStuff' ,
        getterName: 'getOtherStuff' ,
        associationKey: 'otherStuff' ,
        reader: {
            type: 'xml' ,
            root: 'otherStuff' ,
            record: 'otherStuff'
        } ,
        writer: {
            type: 'xml' ,
            documentRoot: 'otherStuff' ,
            record: 'otherStuff'
        }
    }] ,

    proxy: {
        type: 'ajax' ,
        url: '/card' ,
        reader: {
            type: 'xml' ,
            record: 'card' ,
            root: 'card'
        } ,
        writer: {
            type: 'xml' ,
            documentRoot: 'card' ,
            record: 'card' ,
            header: '<?xml version="1.0" encoding="utf-8"?>'
        }
    }
});

ご覧のとおり、各モデルにはリーダーとライターがあります(この最後のモデルは本当に必要ですか?)。

ここでデータを取得し、サーバーに送り返そうとします。

Card.load (1, {
    success: function (card) {
        console.log (card);
        var gd = card.getGeneralData (function (data) {
            console.log (data.get ('name'));
            data.set ('name', 'Another card');
        });

        card.save ();
    }
});

'success'関数が呼び出されると、要求したすべてのXMLが作成され、コンソールに'Aカード'が書き込まれます。次に、「別のカード」でカードの名前を変更し、card.save()を使用してデータを送り返そうとします。この時点で、次の3種類の問題が発生しました。

1)リクエストペイロッド(サーバーに送信されるデータ)は、前のリクエストで取得したXMLではありません。実際、次の構造になっています。

<?xml version="1.0" encoding="utf-8"?>
<card>
    <card>
        <id></id>
    </card>
</card>

私はライターのためにこの構造を手に入れました:2つの等しい要素と新しい要素('id')で空です私はどこにも指定しませんでした。したがって、最初の質問は、送信するデータに単一のdocumentRootまたはrecord要素を追加するにはどうすればよいですか?

2)2番目のポイントは、私のデータはどこにあるのかということです。送信されたXMLが空であるのはなぜですか?モデルの保存プロセスは正しく行われていますか?

3)そして、最後に、3番目の問題:リクエストのContent-Typetext/xmlです。では、どうすればそれをapplication / xmlに変更できますか?

モデルの関連付けは読み取りには問題ありませんが、書き込みでどのように機能するかを実際には理解できません。 私が欲しいのは、XMLデータを読み取り、いくつかのフィールドを変更してから、すべてをXML形式で再送信することです。

4

1 に答える 1

1

私は煎茶フォーラムで尋ねました、そしてそれは答えです:

現時点では、ライターはネストをサポートしていません。

スコット。

だから、今のところ、それは不可能です;)

于 2012-09-11T16:06:51.977 に答える