这是我的页面:
<!DOCTYPE html>
<html>
<head>
<title>Loading from DB</title>
<link rel="stylesheet" href="codebase/webix.css" type="text/css">
<script src="codebase/webix.js" type="text/javascript"></script>
</head>
<body>
<?php
$filename = getcwd() . "/test.txt";
echo $filename;
$line_i_am_looking_for = 5;
$lines = file( $filename , FILE_IGNORE_NEW_LINES );
$lines[$line_i_am_looking_for] = '6my modified line';
file_put_contents( $filename , implode( "\n", $lines ) );
?>
<div class='header_comment'>Test Button</div>
<div id="testB" style='height:600px'></div>
<hr>
<script type="text/javascript" charset="utf-8">
webix.ready(function(){
gridb = webix.ui({
container:"testB",
"view": "form",
"elements": [
{
"view": "textarea",
"name": "woNumber",
"label": "",
"width": 300,
"height": 200,
"options": [
"onViewResize"
],
"value": "",
"placeholder": "WO number (separate with comma if several)",
"labelPosition": "top"
},
{
"view": "button",
"name": "getWODetails",
"label": "",
"value": "Submit",
"options": [
"autowidth:true"
],
on:{
onItemClick:function(id){
webix.message("Test");
}
},
"labelPosition": "top"
},
{
"view": "button",
"name": "getWODetails",
"label": "",
"value": "Passss",
"options": [
"autowidth:true"
],
on:{
onItemClick:function($filename){
webix.message($filename);
}
},
"labelPosition": "top"
}
]
});
});
</script>
</body>
</html>
现在,我正在尝试添加以下代码以便能够在按下Passss按钮时添加一些字符串:
$filename = getcwd() . "/test.txt";
echo $filename;
$line_i_am_looking_for = 5;
$lines = file( $filename , FILE_IGNORE_NEW_LINES );
$lines[$line_i_am_looking_for] = '6my modified line';
file_put_contents( $filename , implode( "\n", $lines ) );
但如果我这样做,就像下面的样本一样,它不起作用:
on:{
onItemClick:function($filename){
$filename = getcwd() . "/test.txt";
echo $filename;
$line_i_am_looking_for = 5;
$lines = file( $filename , FILE_IGNORE_NEW_LINES );
$lines[$line_i_am_looking_for] = '6my modified line';
file_put_contents( $filename , implode( "\n", $lines ) );
}
有没有任何线索如何实现?
答案 0 :(得分:0)
您需要通过按钮的单击来调用服务器端脚本。 像下一个
on:{
onItemClick:function(){
webix.ajax().post("save.php");
}
}
现在,在save.php中,您可以放置必要的逻辑。
如果需要,您可以使用webix.ajax.post的第二个参数向服务器端发送额外的参数
on:{
onItemClick:function(){
//will be $_POST["some"] on a server-side
webix.ajax().post("save.php", { some: this.getValue() });
}
}