1

我正在尝试使用主干从服务器获取数据,这是我的请求:

我用这个初始化视图:

// Backbone view initialize
this.collection = new Dropdown.Collections.Brands();
this.listenTo(this.collection, 'reset', this.render); 

我从我的主干视图将数据发送到我的服务器:

// after the input text fires keypress event
this.collection.fetch({data: {limit: 10, term:value}, reset: true});

我从 PHP 回复这个:

return json_encode($data);

这是响应中的内容:

"{\"brands\":{\"0\":{\"type\":\"brand\",\"id\":\"3\",\"text\":\"Smith\",\"manufacturer\":{\"text\":\"Proctor\",\"id\":\"1\"},\"image\":null}}}"

render函数中,我记录了这个,看看我得到了什么:

console.log(this.collection.toJSON());

这是给我这个的 Chrome 调试器:

在此处输入图像描述

我不确定错误在哪里,我通过跳过fetch方法并使用 ajquery plugin handler作为输入文本尝试了不同的工作方式,但我会用正确的方式来做,问题出在哪里?

两种方法也Response Headers相同。

我通过覆盖以下parse方法解决了这个问题collection

parse:function (response) {
    return jQuery.parseJSON(response);
}

这样它就可以工作了,但是默认情况下它不应该正常工作吗?

4

1 回答 1

0

大声笑,这个问题json_ecode在不同的地方被调用了两次,现在一切都很完美。

于 2013-05-16T10:20:54.043 回答