我怎么能访问localStorage的数据的一部分,使它们在骨干应用程序? [英] How could I access to part of localStorage data and render them in Backbone app?

查看:191
本文介绍了我怎么能访问localStorage的数据的一部分,使它们在骨干应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用localStorage的拯救我的主干应用程序的应用数据。在我的路由器,我用 this.collection.fetch()得到localStorage的数据和渲染他们。但 this.collection.fetch()竟然会在我的localStorage空间取所有的数据,使它们都在观。我想要做的是先获得localStorage的数据,并将其筛选,然后使用这些过滤部分来渲染视图。难道不可能性做到这一点?

I use localStorage to save the app data of my Backbone app. In my router, I use this.collection.fetch() to get the data from localStorage and render them. But this.collection.fetch() actually will fetch all the data in my localStorage space and render them all in View. What I want to do is to get the localStorage data first and filter them, then use these filtered part to render the View. Is it possibile to do this?

推荐答案

这是因为你可能绑定视图到重置收集的事件。

It's because you probably bind the view to the reset event of the collection.

this.collection.on('reset', this.render, this)

如果你想采取反对什么,以使更多的控制权(手动渲染不绑定到事件),你应该避免绑定的事件和呼叫渲染方法,当你需要它做收集适当的过滤后。

If you want to take more control against what to render (manual rendering not binded to events), you should avoid binding that events and call render method when you need it after doing proper filtering of collection.

这篇关于我怎么能访问localStorage的数据的一部分,使它们在骨干应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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