如何将字符串从 Webix textarea 传递给 Button 的函数
How to pass string from Webix textarea to Button's function
这是我的页面:
<!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 ) );
}
有什么线索可以实现吗?
您需要通过单击按钮来调用服务器端脚本。
类似下一个
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() });
}
}
这是我的页面:
<!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 ) );
}
有什么线索可以实现吗?
您需要通过单击按钮来调用服务器端脚本。 类似下一个
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() });
}
}