0

I am still learning backbone and building my first app at the same time, so any help to get the ball rolling again would be awesome.

First, all i am trying to do it is get the proper response from the backbone. I am 100% sure that the server is sending me pure JSON, as I can check it in the browser via a URL. Same url as the urlRoot in my code, its just saved in a var.

I had this kind of working before but i was getting a JSON response through a collection(it look okay), which i later found was not the best, and I would rather get data through models. But I can not seem to get the same return from the server using models.

Here is my code: Model:

        var CalendarDay = Backbone.Model.extend({ 
  urlRoot: daysURL      
});

var calendarItem = new CalendarDay();

Shouldn't I just be able to do this console.log(calendarItem.fetch()) and get the correct JSON response?

This is what my console shows:

What i want is the "responseText" potion only...

This also means that using calendarItem.get(*****) doesnt work.

Any ideas ladies/gents?

4

1 回答 1

0

您在屏幕截图中看到的是由fetch. 此对象表示异步 ajax 调用而不是响应文本。

responseText 是一个列表而不是单个对象。所以calendarItem将包含列表而不是项目属性。试穿console.logcalendarItem.attributes等待fetch完成后。)

如果您只想获取项目,则可以使用函数作为模型的 url 属性 - 然后您可以将 ID 传递给模型并.url()返回该日历项目的资源位置。

于 2013-02-21T22:51:24.087 回答