我正在使用Parse.com和JavaScript开发网站。我有我的“用户”类,但我添加的字段多于默认情况下的字段。
我希望在用户登录时从我的User类(IdGroup)中获取一个特定属性,因此我尝试在登录成功时使用IdGroup
对象捕获user
。
我试过这个:
Parse.User.logIn(username, pass, {
success: function (user) {
//var idGroup = user.get("IdGroup");
localStorage.setItem("parseUser", true);
localStorage.setItem("guestUser", false);
localStorage.setItem("username", username);
user.fetch().then(function (fetchedUser) {
var idGroup = user.get("IdGroup");
localStorage.setItem("IdGroup", idGroup);
});
window.location.href = 'index.html';
},
error: function (user, error) {
alert('Invalid username or password!');
}
});
这不起作用。
如果有人能帮助我,我将非常感激。
谢谢!
答案 0 :(得分:0)
我原以为用户已经在登录时获取了。
但是你的回调函数传入了对象fetchedUser,并且你正在访问用户对象。所以,#include "render.h"
#include "SDL2/SDL.h"
#include <iostream>
#include <fstream>
using namespace std;
const string FILE_NAME = "Orbit.txt";
const int WINDOW_WIDTH = 1280;
const int WINDOW_HEIGHT = 800;
const int SUN_LENGTH = 40;
const int EARTH_LENGTH = 20;
int main() {
//Initialize SDL
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window;
SDL_Renderer *renderer;
window = SDL_CreateWindow(
"test", //title
SDL_WINDOWPOS_CENTERED, //initial x position
SDL_WINDOWPOS_CENTERED, //initial y position
WINDOW_WIDTH, //width
WINDOW_HEIGHT, //height
0 //flags
);
if (window == NULL) {
// In the case that the window could not be made...
printf("Could not create window: %s\n", SDL_GetError());
return 1;
}
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
ifstream file;
file.open(FILE_NAME);
//Prepare render loop
string trash;
string time;
double xPos;
double yPos;
int shorterEdge;
if (WINDOW_HEIGHT < WINDOW_WIDTH) {
shorterEdge = WINDOW_HEIGHT;
} else {
shorterEdge = WINDOW_WIDTH;
}
int numPixelsAU = (shorterEdge/2) - (EARTH_LENGTH/2) - 5;
SDL_Rect sun;
sun.x = ((WINDOW_WIDTH/2) - (SUN_LENGTH/2));
sun.y = ((WINDOW_HEIGHT/2) - (SUN_LENGTH/2));
sun.w = SUN_LENGTH;
sun.h = SUN_LENGTH;
SDL_Rect earth;
//Render loop
while (file >> trash >> time >> trash >> xPos >> trash >> yPos) {
//Clear previous render
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
//Render Sun
SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255);
SDL_RenderDrawRect(renderer, &sun);
SDL_RenderFillRect(renderer, &sun);
//Render Earth
earth.x = ((sun.x + (SUN_LENGTH/2)) + (numPixelsAU*xPos) - (EARTH_LENGTH/2));
earth.y = ((sun.y + (SUN_LENGTH/2)) - (numPixelsAU*yPos) - (EARTH_LENGTH/2));
earth.w = EARTH_LENGTH;
earth.h = EARTH_LENGTH;
SDL_SetRenderDrawColor(renderer, 30, 144, 255, 255);
SDL_RenderDrawRect(renderer, &earth);
SDL_RenderFillRect(renderer, &earth);
SDL_RenderPresent(renderer);
SDL_Delay(50);
}
SDL_Delay(3000);
// Close and destroy the window
SDL_DestroyWindow(window);
// Clean up
SDL_Quit();
return 0;
}
可能就是你要找的东西。