我通常通过转到www.mysite.com
来访问我的Parse应用。
但是,我希望能够执行www.mysite.com/code
或www.mysite.com?page=code
之类的操作,并且无需单击即可显示应用程序中的特定视图。换句话说,我想检测到存在GET变量,并用它来确定显示哪个视图。
有人能指出我正确的方向吗?
您可以使用Backbone's Router。您可以使用an example in the Anypic.org source code。
var AppRouter = Backbone.Router.extend({
routes: {
"pic/:object_id": "getPic",
"*actions": "defaultRoute"
},
getPic: function(object_id) {
App.showLandingPage();
var query = new Parse.Query(Photo);
query.include("user");
query.get(object_id, {
success: function(photo) {
App.landingPageView.showPhoto(photo);
},
error: function(object, error) {
console.error(error);
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and description.
App.landingPageView.showError();
}
});
},
defaultRoute: function(actions) {
App.showHomePage();
}
});
在此示例中,导航到https://anypic.org/pic/XXXXX将调用getPic并将XXXXX的值传递给getPic函数。
我对parse.com不太熟悉,但是如果您只想在javascript中访问GET变量,这并不是很难:
http://www.onlineaspect.com/2009/06/10/reading-get-variables-with-javascript/