Passing data between pages In a SPA using backbone.js

两盒软妹~` 提交于 2019-12-08 12:43:55

问题


Please forgive me if this question sounds very vague. I have looked all over the web and I can’t any examples on how to do this – this added with the fact I am really new to web development put me in a bit of a spot :)

What I am looking to do is have a collection of “gallery” objects (loaded from a local json file) that displays the first image from each as a grid on a single page. When the user clicks an Image, a “galley details” page is loaded and shows the complete gallery plus the title etc.

My question is, how do you go about “passing” the selected item to the next page so the data can be injected and loaded up.

I have been looking into creating a SPA with either backbone or knockout, but right now just something that works and is scalable would be a great start.

As the data source is quite small, I’m not looking at doing any server side stuff. Just client side JS/HTML/CSS.

Kris


回答1:


Perhaps the easiest would be to use localStorage. I'd strongly recommend using a library like store.js to do this:

// before you leave the page
store.set("selected", selectedItem);

// on the new page
var selected = store.get("selected");
if (selected == null)
    selected = defaultValue;


来源:https://stackoverflow.com/questions/14802255/passing-data-between-pages-in-a-spa-using-backbone-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!