骨干持久性从服务器中检索数据,但没有填满的收集和模型 [英] backbone persistence retrieve the data from the server but doesn't fill collection and models

查看:101
本文介绍了骨干持久性从服务器中检索数据,但没有填满的收集和模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始以骨干。我是新来的这一点,我仍然有些困惑。

I'm starting with Backbone. I'm new to this and I'm still somewhat confused.

我有这样的code:

var Item = Backbone.Model.extend();
var Items = Backbone.Collection.extend({
model: Item,
url: 'http://localhost/InterprisePOS/Product/loaditembycategory/Event Materials',
});

var items = new Items();
var onSuccess = function(result){ alert("success"); };

items.fetch({ success: onSuccess });

当我看着萤火虫的反应是某种正确的。它返回正确的数据。但是,当我挖更深的项目是空的。我甚至不知道如何从服务器中使用主干显示数据。任何帮助吗?谢谢

When I look at Firebug the response is somehow correct. It returns the right data. But when I dig much deeper items is empty. I don't even know how to display the data from the server using Backbone. Any help? Thanks

我设法这个以某种方式工作。

i have managed this to somehow work.

from:
var Item = Backbone.Model.extend();
to:
var Item = Backbone.Model;

我可以看到正在填充集合,但只有一个项目。虽然我仍然可以得到它的提醒结果。

I can see the collection being populated but with only one item. Though i still can get it to alert the result.

我设法改正我的成功回调。我现在的问题是我怎么只能打印项目的模式?

i managed to correct my success callback. My question now is how can i print the item model only?

推荐答案

这可能是由于完整的URL,的http:// ... 。当转到jQuery的AJAX调用它会看到的是,假设它是一个外部URL,并把它当作一个跨域请求。您的成功,错误和可能解析函数不会因为运行。

it's probably due to the full url, http://.... when that goes to the jQuery ajax call it will see that, assume it's an external url and treat it as a cross-domain request. Your success, error, and probably parse functions don't run because of that.

此外,你必须在你的URL的最后报价结束后一个逗号。如果你在IE中运行这个,你可能会得到,因为一个JavaScript错误。

Also, you have a comma at the end of your url after the last quote. if you're running this in IE you'll probably get a javascript error because of that.

尝试使用URL作为相对URL。此外,请确保您运行的本地Web服务器下的应用程序,而不是只打开index.html文件在浏览器中。

Try using your url as a relative url. Also, make sure you are running the application under your local web server, and not just opening the index.html file in your browser.

这篇关于骨干持久性从服务器中检索数据,但没有填满的收集和模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆