0

The two console.logs in the code below show the following. The data objects are in json format with 'title', 'position' and 'content'. However, I'm not sure how to view data in a console.log. For example, I tried console.log("data " + data[0].title) to get the title of the first data object, but it returned undefined. As for the 'this' object, I don't actually know what it is. This is the initialize function in a router view of a backbone app, which I'm trying to deconstruct but I can't figure out what 'this' is in this context.

**this** [object Object]



**data** [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

code

 initialize: function (options)
        {

            var _this = this;
            console.log("this " + this);
            $.ajax({
                url: "json/Backboneapp_data.json",
                dataType: 'json',
                data: {},
                async: false,
                success: function (data)
                {
                    console.log("data " + data)
                    _this._data = data;
                    _this._items = new ItemCollection(data);
                    _this._view = new MenuView({ model: _this._items });
                    _this._view.render();
                    Backbone.history.loadUrl();
                }

            });

            return this;
        },
4

1 に答える 1

0

文字列に追加すると、オブジェクトは文字列にキャストされます。オブジェクトだけを console.log にすると、多くの環境 (Web Kit インスペクタなど) でコンソール内のオブジェクトを検査できます。

console.log(this)
于 2012-10-20T19:32:22.480 に答える