通过将数据存储在json中并将json值与用户输入值进行比较,创建登录页面和身份验证sapui5
View1.view.xml products.json通过将数据存储在json中并将json值与用户输入值进行比较,创建登录页面和身份验证sapui5,sapui5,Sapui5,View1.view.xml products.json 我已经尝试过将此代码用于登录和身份验证,但在我用于从视图到控制器获取JSON值时,由于未定义getValue而出现错误,有人能给出解决方案吗?那么,您的验证方法代码是什么样子的?sap.ui.getCore().byId(“a1”).getValue()将抛出错误,因为“a1”是文本的id而不是输入的id。您必须使用getText()来读取显示的字符串。“a1”不仅是一个文本控件,它也是聚合/Items的一部分,因此可能会有更多这样的项(
我已经尝试过将此代码用于登录和身份验证,但在我用于从视图到控制器获取
JSON
值时,由于未定义getValue
而出现错误,有人能给出解决方案吗?那么,您的验证方法代码是什么样子的?sap.ui.getCore().byId(“a1”).getValue()
将抛出错误,因为“a1”是文本的id
而不是输入的id
。您必须使用getText()
来读取显示的字符串。“a1”不仅是一个文本控件,它也是聚合/Items
的一部分,因此可能会有更多这样的项(记住,ID只能使用一次!)最好使用数据绑定和模型数据,而不是getValue()/getText()
so,验证
方法代码的外观如何?sap.ui.getCore().byId(“a1”).getValue()
将抛出错误,因为“a1”是文本
的id,而不是输入
。您必须使用getText()
来读取显示的字符串。“a1”不仅是一个文本控件,它也是聚合/Items
的一部分,因此可能会有更多这样的项(记住,ID只能使用一次!)最好使用数据绑定和模型数据,而不是getValue()/getText()
<mvc:View xmlns:f="sap.ui.layout.form" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" controllerName="Login.controller.View1">
<App>
<pages>
<Page title="Login">
<f:SimpleForm maxContainerCols="2" editable="true" layout="ResponsiveGridLayout" labelSpanL="4" labelSpanM="4" emptySpanL="0" emptySpanM="0" columnsL="2" columnsM="2">
<f:content>
<Input width="100%" id="__input0" placeholder="UserID" liveChange="true" />
<Input width="100%" id="__input1" type="Password" placeholder="Password" />
<Button text="Login" width="100px" id="__button0" type="Accept" press="Validation" />
</f:content>
</f:SimpleForm>
<Table items="{ path: '/Item' }" id="tableID" width="90%">
<items>
<ColumnListItem counter="0" id="__item0">
<cells>
<Text id="a1" text="{OrderID}" />
<Text text="{Quantity}" />
</cells>
</ColumnListItem>
</items>
<columns>
<Column id="__column0">
<header>
<Label text="OrderID" id="__label0" />
</header>
</Column>
<Column id="__column1">
<header>
<Label text="Quantity" id="__label1" />
</header>
</Column>
</columns>
</Table>
<content/>
</Page>
</pages>
</App>
</mvc:View>
sap.ui.define(["sap/m/MessageToast",
"sap/ui/core/mvc/Controller", 'sap/ui/model/json/JSONModel'
], function(MessageToast, Controller, JSONModel) {
"use strict";
return Controller.extend("Login.controller.View1", {
onInit: function(oEvent) {
// set explored app's demo model on this sample
var oModel = new JSONModel(jQuery.sap.getModulePath("Login", "/model/Products.json"));
sap.ui.getCore().setModel(oModel);
this.getView().byId("tableID").setModel(oModel);
// this.getView().byId("samplepie").setModel(oModel);
},
Validation: function() {
var UserID = this.getView().byId("__input0").getValue();
var Password = this.getView().byId("__input1").getValue();
if (UserID == "") {
MessageToast.show("Please Enter UserID");
return false;
} else if (Password == "") {
MessageToast.show("Please Enter Password");
return false;
} else if (UserID == sap.ui.getCore().byId("a1").getValue()) {
MessageToast.show("authenticated ");
}
}
});
});
{
"Item": [{
"OrderID": "1100M",
"Quantity": 100
}, {
"OrderID": "11001I",
"Quantity": 250
},
{
"OrderID": "11002D",
"Quantity": 400
}
]
}