这是我的代码
"use strict";
alert("WORKING");
var tableName = "EmployeeCred";
// Add an event listener to call our initialization routine when the host is ready
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
alert("DeviceOnready WORKING");
$('#add-item').submit(authenticateLogin);
}
function authenticateLogin() {
alert("AUTENTHICATE WORKING");
var row, numItemsRead;
var user = document.getElementById('usernameInput').value
var pass = document.getElementById('passwordInput').value
alert("Username submitted "+user);
alert("Password submitted " + pass);
alert("creating server database connection");
var client = new WindowsAzure.MobileServiceClient('https://strivedatabaseapp.azurewebsites.net'); // define the client
alert("connection finished");
var table = client.getTable(tableName);
alert("reading table soon");
我的意图是尝试遍历数据库,直到找到与从输入登录屏幕获取的用户名/密码值均匹配的值。我知道我将整个数据库表分配到了变量表中,但是我不知道如何遍历代码。我尝试了多种方法,但似乎无法弄清楚。我相信我必须要做一个table.read()。then(),但是我似乎无法使其工作。有什么帮助吗?请谢谢!
我的最终目标是做某事
if (userInput == userDatabase || passInput == passDatabase) {
alert("You did it! You logged in!");
//code which passes user to next page
}
答案 0 :(得分:0)
我假设您要过滤服务器上的数据。您可以从此document中获得答案。
您可以在表引用上使用where子句:
table
.where({ userId: user.userId, complete: false })
.read()
.then(success, failure);
您还可以使用过滤对象的功能。在这种情况下,此变量分配给要过滤的当前对象。以下代码在功能上等同于先前的示例:
function filterByUserId(currentUserId) {
return this.userId === currentUserId && this.complete === false;
}
table
.where(filterByUserId, user.userId)
.read()
.then(success, failure);