4

私は本当に奇妙な問題を抱えています。サブオブジェクトにアクセスしようとしていますが、機能しません。最も簡単な方法は、FireBugのコンソール出力を表示することです。

console.log(DesignDocument)

DesignDocument: mwrNsBrowser
    html: e.fn.e.init[1]
    name: "Game Design Document"
    rootName: "Game Design Document"
    __proto__: Object
        afterLoadCategory: function (bitData, catName)...
        bits: Object
        hide: function ()...
        html: ""
        loadCategory: function (catName, parentBit)...
        name: ""
        rootName: ""
        show: function ()...
        tmp: Object

今、私はプロトタイプで定義された「ビット」オブジェクトにアクセスしようとしています。うまくいきます。

console.log(DesignDocument.bits)

Object
    DocumentSet1: Array[1]
        0: mwrBrowserBit
        length: 1

しかし、ここに問題があります。「DocumentSet1」配列を取得しようとしています。

var selector = "DocumentSet1";
console.log(DesignDocument.bits[selector])

undefined

そして、それは単に「未定義」を返します!私は現在、なぜこれが機能しないのかについての考えがありません。誰かが私があまりにも馬鹿だったと私に言うことができることを願っています...

4

1 に答える 1

0

配列 DocumentSet1 は DesignDocument.bits オブジェクトのプロパティであるため、コンソールにログを記録する正しい構文は次のようになります。

console.log(DesignDocument.bits.DocumentSet1);

または、配列内の特定のアイテムを表示する場合:

console.log(DesignDocument.bits.DocumentSet1[num]);
于 2012-11-18T15:05:32.560 に答える