Passing data between pages In a SPA using backbone

2019-06-08 20:32发布

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条回答
兄弟一词,经得起流年.
2楼-- · 2019-06-08 21:15

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;
查看更多
登录 后发表回答