块引用 我需要一个下拉菜单,用户可以选择任何单位(MM或Inches.toggle),所以如果我选择值mm,在我的下面的表格中,所有的计算都应该用mm来完成。这意味着所有的值都应该以mm显示。并按下拉列表中选择的单位计算。 例如。长度,宽度和总面积都将以MM显示和计算(基于下拉选择)
form2Object: function(form) {
var data = null;
if ((typeof form) == 'string') {
form = document.getElementById(form);
}
if (form) {
data = new Object();
for (var i = 0; i < form.elements.length; i++) {
if ( (form.elements[i].tagName.toUpperCase() == 'INPUT' &&
form.elements[i].type.toUpperCase() != 'CHECKBOX')
||
form.elements[i].tagName.toUpperCase() == 'TEXTAREA') {
data[form.elements[i].name] = form.elements[i].value;
} else if (form.elements[i].tagName.toUpperCase() == 'SELECT') {
data[form.elements[i].name] = form.elements[i].value;
} else if (form.elements[i].tagName.toUpperCase() == 'INPUT' &&
form.elements[i].type.toUpperCase() == 'CHECKBOX') {
var checkbox = $(form.elements[i]);
if (checkbox.prop("checked") == true){
data[form.elements[i].name] = true;
} else if (checkbox.prop("checked") == false){
data[form.elements[i].name] = false;
}
}
}
}
return data;
}
&#13;
答案 0 :(得分:0)
您需要定义单位变量才能访问它。 例如:
CREATE OR REPLACE PACKAGE PKG_USERINFO AS
TYPE TY_USERINFO_RECORD IS RECORD( U_ID VARCHAR2(50),
U_NAME VARCHAR2(50),
DOB DATE);
TYPE TY_USERINFO_TABLE IS TABLE OF TY_USERINFO_RECORD;
FUNCTION FN_GET_USERINFO_ROWS(P_USER_ID IN NUMBER)
RETURN TY_USERINFO_TABLE PIPELINED;
END PKG_USERINFO;
答案 1 :(得分:0)
我稍微修改了你的代码。希望它有所帮助!!
var app = angular.module('myapp', []);
app.controller('MainCtrl', function($scope) {
$scope.change = function() {
if ($scope.data.previousSel != $scope.data.selectedOption) {
var diff = $scope.data.previousSel.id - $scope.data.selectedOption.id;
angular.forEach($scope.choices, function(choice) {
choice.length = Math.pow(10, diff) * choice.length;
choice.width = Math.pow(10, diff) * choice.width;
});
$scope.data.previousSel = $scope.data.selectedOption;
}
};
$scope.data = {
availableOptions: [{
id: '1',
name: 'mm'
}, {
id: '2',
name: 'cm'
}, {
id: '4',
name: 'm'
}],
previousSel: {
id: '4',
name: 'm'
},
selectedOption: {
id: '4',
name: 'm'
} //This sets the default value of the select in the ui
};
$scope.choices = [{
id: 'choice1',
length: 0,
width: 0
}, {
id: 'choice2',
length: 0,
width: 0
}];
$scope.addNewChoice = function() {
var newItemNo = $scope.choices.length + 1;
$scope.choices.push({
'id': 'choice' + newItemNo
});
};
$scope.removeChoice = function() {
var lastItem = $scope.choices.length - 1;
$scope.choices.splice(lastItem);
};
$scope.sum = function() {
var sum = 0;
angular.forEach($scope.choices, function(choice) {
sum += choice.length * choice.width;
});
return sum;
}
});
&#13;
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body>
<div ng-app="myapp" ng-controller="MainCtrl">
<p>Select a unit:</p>
<select ng-change="change()" ng-model="data.selectedOption" ng-options="option.name for option in data.availableOptions track by option.id">
</select>
<form data-ng-repeat="choice in choices">
Length:
<input type="number" ng-model="choice.length" />width:
<input type="number" ng-model="choice.width" />Area:
<input id="area" type="number" placeholder="Area" value="{{ choice.length * choice.width }}" />
<button ng-show="$last" ng-click="removeChoice()">-</button>
</form>
<button ng-click="addNewChoice()">Add fields</button>
Result : {{ sum() }}
</div>
</body>
</html>
&#13;