我需要根据用户输入进行乘法计算。因此,用户必须在输入A和输入B中输入一个值,然后输入C会自动计算输入A和输入B之间的乘法。有人对在sapui5中执行该操作有任何想法吗?
我尝试使用格式化程序为值输入C进行计算,但似乎没有用。输入输入B后,输入C中没有值
<Label text= "Rate"/>
<Input id ="Project Rate" value=""/>
<Label text="Discount"/>
<Input type="Number" id="inputB"/>
<Label text="Total Rate"/>
<Input id="inputC" enabled="false"
value="{parts:[
{path: '/ProjectRate'},
{path: '/Discount'},
{path: '/TotalRate'}],
formatter: 'calcProjectRate'}"/>
calcProjectRate: function(ProjectRate, Discount, TotalRate) {
if (ProjectRate && Discount) {
TotalRate = ProjectRate * Discount / 100;
return TotalRate;
}
return "0";
答案 0 :(得分:0)
您的代码有错误,您需要检查您的IDE代码检查结果。
下面的工作示例(可能不是最佳解决方案)。
sap.ui.getCore().attachInit(function() {
"use strict";
sap.ui.controller("MyController", {
onInit: function() {
}
});
sap.ui.xmlview({
viewContent: jQuery("#myView").html()
}).placeAt("content");
});
calcProjectRate = function() {
ProjectRate = this.oView.byId("ProjectRate").getValue();
Discount = this.oView.byId("inputB").getValue();
TotalRate = 0;
if (ProjectRate && Discount) {
TotalRate = ProjectRate * Discount / 100;
}
this.oView.byId("inputC").setValue(TotalRate);
}
<!DOCTYPE html>
<title>SAPUI5</title>
<script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js" id="sap-ui-bootstrap" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-libs="sap.m" data-sap-ui-bindingSyntax="complex" data-sap-ui-compatVersion="edge" data-sap-ui-preload="async"></script>
<script id="myView" type="ui5/xmlview">
<mvc:View controllerName="MyController" xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:layout="sap.ui.commons.layout">
<layout:MatrixLayout>
<layout:rows>
<layout:MatrixLayoutRow>
<layout:MatrixLayoutCell backgroundDesign="Fill1" padding="None">
<Input id="ProjectRate" value="" liveChange="calcProjectRate" />
<Label text="Discount" />
<Input type="Number" id="inputB" />
<Label text="Total Rate" />
<Input id="inputC" enabled="false" />
</layout:MatrixLayoutCell>
</layout:MatrixLayoutRow>
</layout:rows>
</layout:MatrixLayout>
</mvc:View>
</script>
<body class="sapUiBody">
<div id="content"></div>
</body>