开发者

How to access content in an object literal?

Can someone tell me wha开发者_如何学运维t the best way is to store content in an object literal and how to access it using my JS pattern? I can't seem to get it to work.

Namespace.object = {
    var data = [{"myid1" : "<p>My content 1</p>"}];

    method: function () {
        var myData = Namespace.object.data[0].id;
    }
};


To store:

Namespace.object = {
    data: [{"myid1" : "<p>My content 1</p>"}],

    method: function () {
        var myData = Namespace.object.data[0].id;
    }
};

To access:

var theFirstData = Namespace.object.data[0];

var myId1 = Namespace.object.data[0].myid1;

// Alternatively...
var myId1b = Namespace.object.data[0]['myid1'];

Namespace.object.method();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜