BackboneJS collection.reset()VS collection.fetch() [英] BackboneJS collection.reset() vs collection.fetch()

查看:239
本文介绍了BackboneJS collection.reset()VS collection.fetch()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读并在这两种方法阅读文档,但对我的生活不能工作了,为什么你可以使用一个比其他?

I have read and read the docs on these two methods, but for the life of me cannot work out why you might use one over the other?

可能有人给我一个基本的code的情况,其中一个是应用程序和其他不会的。

Could someone just give me a basic code situation where one would be application and the other wouldn't.

推荐答案

重置 设置集合与模型的数组指定:

reset sets the collection with an array of models that you specify:

collection.reset( [ { name: "model1" }, { name: "model2" } ] );

从服务器检索收集数据,使用网址您为集合指定。

fetch retrieves the collection data from the server, using the URL you've specified for the collection.

collection.fetch( { url: someUrl, success: function(collection) {
    // collection has values from someUrl
} } );


这里说明的差异小提琴。

这篇关于BackboneJS collection.reset()VS collection.fetch()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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