[英]i want to display the matching records in the console in javascript
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script type = "text/javascript"
src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
</head>
<body>
<form id = 19>
<form name = "login">
<h4>product ID </h4>
<input type = "text" id = "100">
<h4> Product Title</h4>
<input type = "text" id = "101">
<h4> startdate</h4>
<input type = date id = "102">
<br><button type="submit" form="nameform" onclick="goodfunction()" value="Submit">Submit</button>
</form>
<script>
function goodfunction(){
var url = "xxxxxxxxxxxxxxxx";
$.getJSON(url, function( data ) {
console.log(data);
//console.log("AllData")
var obj = data['AllData'];
console.log(obj);
var l = obj.length
console.log(l);
for(var i=0;i<obj.length;i++){
var a= $( "#100" ).val();
var b= $( "#101" ).val();
var c = $( "#102" ).val();
if (a ==obj[i]["ProductID"] || b==obj[i]["Title"] || c==obj[i]["startDate"] ){
console.log(a);
console.log(b);
}
}
})
}
</script>
</body>
</form>
</html>
1)I have totally three text boxes i am having a rest api which gets all the data i want to search the matching records 1)我总共有三个文本框,我有一个rest api,它可以获取我想要搜索匹配记录的所有数据
2) if the user enters the start date we should get all the matching records of start date matching to the text 2)如果用户输入开始日期,我们应该得到开始日期与文本匹配的所有匹配记录
3)i am having 3 text fields i want to get data which is only matching to all the three text Fields (means common to start date , id and title) 3)我有 3 个文本字段,我想获取仅与所有三个文本字段匹配的数据(意味着开始日期、ID 和标题通用)
4)I am done with or condition but i coudn't figure out how to match the requirement of 3 step please help me i want both 2 and 3 functionalities 4)我完成了或条件,但我不知道如何匹配 3 步的要求,请帮助我我想要 2 和 3 功能
If you already have the conditional done如果你已经完成了条件
if (a ==obj[i]["ProductID"] || b==obj[i]["Title"] || c==obj[i]["startDate"] ){
console.log(a);
console.log(b);
}
this contitional.这个条件。 Then requirement 3, for all three matching would be
然后要求 3,对于所有三个匹配将是
if (a ==obj[i]["ProductID"] && b==obj[i]["Title"] && c==obj[i]["startDate"] ){
console.log(a);
console.log(b);
}
this would only return true if all three text feilds are matching.如果所有三个文本字段都匹配,这只会返回 true。
I would change your for loop to something more like我会把你的 for 循环改成更像
var a= $( "#100" ).val();
var b= $( "#101" ).val(); // There is no need to recreate these variables every time. once is enough.
var c = $( "#102" ).val();
for(var i=0;i<obj.length;i++){
if (a ==obj[i]["ProductID"] && b==obj[i]["Title"] && c==obj[i]["startDate"] ){
console.log(a);
console.log(b);
console.log(C);
}
else if (a ==obj[i]["ProductID"] || b==obj[i]["Title"] || c==obj[i]["startDate"]){
console.log(a);
console.log(b);
}
as for requirement 2, something like至于要求 2,类似
if (c==obj[i]["startDate"] ){
console.log(a);
console.log(b);
console.log(C);
}
Would get you all the records for each element matching the start date making your for loop look like将为您提供与开始日期匹配的每个元素的所有记录,使您的 for 循环看起来像
var a= $( "#100" ).val();
var b= $( "#101" ).val(); // There is no need to recreate these variables every time. once is enough.
var c = $( "#102" ).val();
for(var i=0;i<obj.length;i++){
if (c==obj[i]["startDate"] ){
console.log(a);
console.log(b);
console.log(C);
}
if (a ==obj[i]["ProductID"] && b==obj[i]["Title"] && c==obj[i]["startDate"] ){
console.log(a);
console.log(b);
console.log(C);
}
else if (a ==obj[i]["ProductID"] || b==obj[i]["Title"] || c==obj[i]["startDate"]){
console.log(a);
console.log(b);
}
}
As for the bottom of your page.至于你的页面底部。 I would change
我会改变
}) // Missing semicolon
}
</script>
</body>
</form> <!-- Needs to be closed inside of the body tag -->
</html>
to this:对此:
});
}
</script>
</form>
</body>
</html>
I'm not sure why you have a form inside of a form, but okay.... The following code above should help you with your test.我不知道为什么你在一个表单里面有一个表单,但是好吧......上面的代码应该可以帮助你进行测试。 If I have misunderstood your question please feel free to clarify.
如果我误解了您的问题,请随时澄清。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.