자바를 사용하여 티타늄에서 앱을 개발 중이며 다음 확인 로직을 구현하려고합니다 :
사용자가 1과 200 사이의 값 하나를 입력 한 다음/그녀는 1과 첫 번째 값 사이의 범위에있는 두 번째 값을 입력해야합니다 (작거나 같지만 첫 번째 값은 더 이상 없습니다). 예를 들어티타늄/자바 스크립트 범위의 수를위한 조건
var value_alert = ''; //First value
var value_remind = ''; //Second value (should be less or equal)
var default_value_alert = 10; //Default first value for TextField
var default_value_remind = 5; //Default second value for TextField
// handle and save the first value entered by user
function doOpenAlert(){
var input_text = Ti.UI.createTextField({
keyboardType: Ti.UI.KEYBOARD_PHONE_PAD
});
if(value_alert === ''){
input_text.value = default_value_alert;
} else {
input_text.value = value_alert;
}
var dialog = Ti.UI.createOptionDialog({
title : "Specified distance in the range 1-200 km",
androidView : input_text,
buttonNames : ['Ok', 'Cancel']
});
dialog.show();
dialog.addEventListener('click', function(e){
if(value_remind === ''){
value_remind = default_value_remind;
}
if(e.index == 0){ // Check is Ok pressed
// check_number = isInt(input_text.value);
if(input_text.value >= 1 && input_text.value <= 200){ // Check that the first value is in range
var toast = Titanium.UI.createNotification({
duration: 2000,
message: "Distance is " + input_text.value + " km."
});
toast.show();
value_alert = input_text.value; // Saving the first value entered by user
} else if(input_text.value == 0){
alert("The field is empty.");
} else if(!(input_text.value >= 1 && input_text.value <= 200)){
alert("Range is between 1 and 200 km.");
}
}
});
}
// handle and save the second value entered by user
function doOpenMinne(){
var input_text = Ti.UI.createTextField({
keyboardType: Ti.UI.KEYBOARD_PHONE_PAD
});
if(value_remind === ''){
input_text.value = default_value_remind;
} else {
input_text.value = value_remind;
}
var dialog = Ti.UI.createOptionDialog({
title : "Remind before number",
androidView : input_text,
buttonNames : ['Ok', 'Cancel']
});
dialog.show();
dialog.addEventListener('click', function(e){
if(value_alert === ''){
value_alert = default_value_alert;
}
if(e.index == 0){
// check_number = isInt(input_text.value);
if(input_text.value >= 1 && input_text.value <= value_alert){ // Check if the second value in is range between 1 and the first value
var toast = Titanium.UI.createNotification({
duration: 2000,
message: "Remind at " + input_text.value + " km."
});
toast.show();
value_remind = input_text.value; // Saving the second value entered by user
} else if(input_text.value == 0){
alert("The field is empty");
} else if(!(input_text.value >= 1 && input_text.value <= 200)){
alert("The range is between 1 and 200 km");
}
}
});
}
, 그것은 다음과 같은 조합에서 잘 작동 : 여기
내 코드입니다1) 첫 번째 값 - (10); 두 번째 값 - 5;
2) 첫 번째 값 - 105; 두 번째 값 - 101;
첫 번째 값이 100보다 크지 만 두 번째 값이 < 100 - 인 경우 중요한 것은 작동하지 않습니다..
조건은 정확하지만 잘못 작동하는 것 같습니다. 실수를 찾을 수 없습니다.
에반 감사합니다! 당신은 맞습니다 - 다른 유형입니다. 이제 제대로 작동합니다. – devger