0

因此,由于无缝数据绑定,我刚刚开始将正在进行的旧站点转换为使用 angular 而不是 jquery。

现在我有了这个用数据集填充的选择;

<select ng-model="affiliation" ng-options="row.desc for row in affiliationTable"> <!--group by row.id-->
     <option value=""> Select an existing affiliation</option>
</select>

当用户单击表格中的锚标记时,我希望在选择中选择相应的“从属关系”,因此我的表格如下所示;

<tr ng-repeat="row in tableData">  <!--{{row.name}}-->
     <td><a href='#' ng-click="invokeModal();" onclick="lastClickedMember=this.id;" id="{{row.id}}">{{row.name}}</a></td>
     <td>{{row.active}}</td>
     <td>{{row.end_date}}</td>
     <td>{{row.start_date}}</td>
</tr>

这是我用来尝试选择特定选项的代码;

$scope.invokeModal = function(){ //memberDescription

    for(var row in $scope.tableData){
        if($scope.tableData[row].id == lastClickedMember){
            $scope.selectedMembershipDescription = $scope.tableData[row].desc;


            $scope.selectedMembershipId = lastClickedMember;
            $scope.selectedEndDate = $scope.tableData[row].end_date;
            $scope.selectedStartDate = $scope.tableData[row].start_date;
        }

        if($scope.affiliationTable[row].id == lastClickedMember){
            $scope.affiliation = $scope.affiliationTable[row]; //$scope.selectedMembershipDescription;
        }
    }

    jQuery("#mem").modal('show');
};

当然,在尝试了这段代码和其他一些选项之后,我的选择仍然没有填充任何选项。

有人能帮助我吗。

编辑 这里是表格的填充方式;

$http(
    {
        url: "http://localhost/get_info.php",
        method: "POST",
        data: "filter=membership&cid=2",
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    }
).
success(function(data, status, headers, config) {
    // this callback will be called asynchronously
    // when the response is available
    //alert("first row: " + data.name[0]);
    for(var row in data.name){
        $scope.tableData.push({id:data.name[row][0], name:data.name[row][5], active:(data.name[row][1] == "0") ? "Not Active" : "Active", end_date:data.name[row][3], start_date:data.name[row][2]});
    }
});

//get affiliation table
$scope.affiliationTable = [];

$http({
        url: "http://localhost/get_info.php",
        method: "POST",
        data: "filter=affiliation",
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data, status, headers, config) {
    // this callback will be called asynchronously
    // when the response is available

    for(var row in data.name){
        $scope.affiliationTable.push({id:data.name[row][0], desc:data.name[row][1]});
    }
});
4

1 回答 1

1

尝试

<tr ng-repeat="row in tableData">
    <!--{{row.name}}-->
    <td><a href='#' ng-click="invokeModal(row);" id="{{row.id}}">{{row.name}}</a>

    </td>
    <td>{{row.active}}</td>
    <td>{{row.end_date}}</td>
    <td>{{row.start_date}}</td>
</tr>

$scope.invokeModal = function (row) { //memberDescription
    $scope.selectedMembershipDescription = row.desc;
    $scope.selectedMembershipId = row.id;
    $scope.selectedEndDate = row.end_date;
    $scope.selectedStartDate = row.start_date;

    angular.forEach($scope.affiliationTable, function (affiliation) {
        if (affiliation.id == row.id) {
            $scope.affiliation = affiliation;
        }

    })
    jQuery("#mem").modal('show');
};
于 2013-10-02T10:39:25.303 回答