我希望在public static changesMade: Subject<any> = new Subject();
//inside constructor the following
ParentComponent.changesMade.subscribe(res => {
//call your method here, with the res (someData) you receive from child
this.doThisWhenChildEmits(res);
});
更改时从数据库获取订单信息及其日期。
请用书面代码帮助我,因为我还是PHP新手。
CODE:
public clickToSendBack(){
// send the data to parent
ParentComponent.changesMade.next(someData)
}
答案 0 :(得分:0)
如果我理解正确:你想要执行一些PHP代码,用数据库日期检查数据日期保存在数据库中。当datepicker输入字段发生更改时,您希望执行该PHP代码
要完成此操作,您可以使用Ajax调用。通过Ajax调用,您可以从php文件中获取结果,而无需重新加载页面。我建议使用Jquery和Bootstrap datapicker。当然你可以使用另一个datepicker插件,但是你需要查看该文档如何在日期更改时执行js函数。
使用Bootstrap数据贴图,它将如下所示
$('#datepicker').datepicker().on('changeDate', function () {
//js code executed when #datepicker data changes
//get te data
var datepickerDate = $('#datepicker').val(); //date of datepicker
var data = {datepickerDate: datepickerDate};
var json = JSON.stringify(data);
var url = "check_date.php" //URL to a php file, I would call it check_date.php
//set up ajax call
$.ajax({
method: "POST",
url: url,
data: {data: json}
})
.done(function( result ) {//when the ajax call was successfully executed
//we will add things here later
});
});
这会将datepicker inputvield的日期发送到名为check_data.php
的php文件
check_data.php
将如下所示:
<?php
if(isset($_POST['data'])) {//check if data has been send
/* we made a json of data so we first need to decode the json.
We can access data with $_POST because we used the method POST in the ajax call*/
$data = json_decode($_POST['data']);
/* now define the variable $date to the $date you send with POST */
$date = $data->datepickerDate;
/* now you need the date saved in your database */
$DBdate = "Put your database date here";
/* now you can check if they are equal */
if($date == $DBdate) {
echo 'true'; //when dates are equal
} else {
echo 'false'; //when dates are not equal
}
}?>
此文件现在将返回true或false,具体取决于datebasedate是否等于datepicker-date
这意味着我们现在可以对ajax调用完成时的操作进行编程
.done(function( result ) {//when the ajax call was successfully executed
//result will be the result the php file gives us (true or false)
if(result == true) {
//display your table
} else {
//do nothing or inform the user that the dates do not match
}
});