我在将事件绑定到 AJAX 填充的列表项时遇到问题.我希望能够打开表单并根据列表项值填写其字段



我正在构建一个数据输入应用程序,其中我们有两种形式。这是我的代码,其中列表项显示在无序列表中。单击列表项时,新表单应填充新表单中每个文本框中的相应条目,这些条目取自所选列表项。

这是发送到原始窗体的列表项的代码

include_once("test1.php");
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$search= $request['search'];
$searchLabel= $request['searchItem'];
$newConnect= new connect();
$newConnect->dataform($search, $searchLabel);
class connect
{
public function dataform($search, $searchLabel)
{
$test= new db_test1();
$test->build_search($search, $searchLabel);
$i = 1;
while ($test->build_fetch(3))
{
$test_array = array();
$test_array[0] = $test->src->PersonID;
$test_array[1] = $test->src->LastName;
$test_array[2] = $test->src->FirstName;

foreach ($test_array as $ele)
{
$stmt .= <<<HTML
<div style="display: inline-block; width: 33%; padding: 20px;" >$ele</div>
HTML;
}
echo <<<HTML
<li  tabindex="$i" id="listSelect" data-ng-model="model.$test_array[0]" 
data-ng-dbl-click="showForm()" class="list-group-item" style="li">$stmt</li>
HTML;
$i++;
}
}
}

以及原始表单文件中的 HTML 部分,它将通过 ng-bind html 将列表项接收到无序列表中,作为上述代码的响应

<div class="panel-body" data-ng-show="searchForm.$submitted">
<button class="btn btn-success text-right" data-ng- 
click="showForm()">EDIT</button>
<ul class="list-group" data-ng-bind-html="templateURLSearch">
</ul>
</div> 

应用程序的控制器

var app = angular.module("myApp", []);
app.controller('myCtrlSearch', function ($scope, $http , $sce) {
$scope.runSearch = function () {

$http({
method: 'POST',
url: 'Connect-test1.php',
data: {
search: $scope.search,
searchItem: $scope.searchItem
},
headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
}).then(function (response) {
$scope.templateURLSearch= $sce.trustAsHtml(response.data);
})
};
});

我在接收列表元素作为 html 并将事件绑定到它们以在控制器中进行管理时遇到问题。 我找到了另一种解决方案,而不是发送 html 作为响应,而是发送值作为响应并填写到表单中的现有 html 中。

include_once("test1.php");
$postdata = file_get_contents("php://input");
$request = json_decode($postdata, true);
$search= $request['search'];
$searchLabel= $request['searchItem'];
$newConnect= new connect();
$newConnect->dataform($search, $searchLabel);

class connect
{
public function dataform($search, $searchLabel)
{
$test= new db_test1();
$test->build_search($search, $searchLabel);
$test_array = array();
$i = 0;
while ($test->build_fetch(3))
{
$test_array[$i]['ID'] = trim($test->src->PersonID, '""');
$test_array[$i]['lastname'] = $test->src->LastName;
$test_array[$i]['firstname'] = $test->src->FirstName;
$i++;
}
$json= json_encode($test_array);
echo $json;
}
}

我把html改成了这个

<div class="panel-body" data-ng-show="searchForm.$submitted" style="background- 
color: #F0F8FF;">
<ul class="list-group">
<li  data-ng-repeat="row in rows track by $index">
<div style="display: inline-block; width: 25%; padding: 20px;" > 
{{row.ID}}</div>
<div style="display: inline-block; width: 25%; padding: 20px;" > 
{{row.lastname}}</div>
<div style="display: inline-block; width: 25%; padding: 20px;" > 
{{row.firstname}}</div>
<button class="btn btn-success text-right" data-ng- 
click="showFilled(row)">EDIT</button>
</li>
</ul>
</div>   

最新更新