Angularjs Highlight在排序名称后显示最后一行(即$ index)

时间:2014-04-16 12:45:10

标签: angularjs sorting indexing

我很抱歉定期发布有关Angularjs的问题,我是新手,并且很多因为这就是我发布问题的原因。

我怀疑的是,每当我创建一个新列表时,我都会有一个名称列表,突出显示正在创建的名称,但是当我尝试按字母顺序设置这些名称时,突出显示的问题是显示新的$ index值正在加入。我试图传递id代替$ index而不是高亮也没有显示。这是我试过的代码

<table data-ng-repeat="SupplierModels in Supplierlist | filter:suppliersearch">
    <tr>
        <td class="roundedCorners6_account" ng-class='{roundedCorners6_account_active: $index==selectedRowslist}' style="width: 200px; cursor: pointer; text-align: center;">
            <div ng-click="showSupplier(SupplierModels.supplier_ID, $index)">{{SupplierModels.supplier_Name | truncate}}</div>
        </td>
    </tr>
</table>

$ scope函数是

function initialLoading() {
    ServiceFactory.Invoke(baseurl + 'Api/SupplierApi/SupplierList').success(function (success) {
        $scope.Supplierlist = success;
    }).error(function (error) {
        alert(error);
    })
}

$scope.SaveSupplier = function () {
    $scope.IsValidatesupplierData($scope);
    if ($rootScope.alerts.length == 0) {
        ServiceFactory.InvokeWithParameters(baseurl + 'Api/SupplierApi/SaveSupplier', $scope.supplier).success(function (success) {
            initialLoading();
            var rows = $scope.selectedRowslist == undefined ? $scope.Supplierlist.length : $scope.selectedRowslist;
            var supId = success;
            $scope.showSupplier(supId, rows);
            $scope.visible = true;
        }).error(function (error) {
            alert(error);
        })
    }
    else {
        $rootScope.isErrorPopUpShow = true;
    }
}

$scope.showSupplier = function (id, rows) {
    $scope.visible = true;
    ServiceFactory.InvokeWithParameters(baseurl + 'Api/SupplierApi/SupplierDetail?supplierId=' + id).success(function (success) {
        $scope.supplier = success;
        $scope.selectedRowslist = rows;
    }).error(function (error) {
        alert(error);
    })
}

Example View

我希望我给出了适当的解释。感谢

1 个答案:

答案 0 :(得分:0)

我认为在数据模型中使用自然ID会更好。   id会有效,但supplier是否有id字段?如果是这样,你可以使用它。

<td class="roundedCorners6_account" 
    ng-class='{roundedCorners6_account_active: activeSupplierID== SupplierModels.supplier_ID}'

$scope.showSupplier = function (id, rows) {
    $scope.visible = true;
    ServiceFactory.InvokeWithParameters(baseurl + 'Api/SupplierApi/SupplierDetail?supplierId=' + id).success(function (success) {
        $scope.supplier = success;
        $scope.activeSupplierID = id;  //supplier.id ? if it exists.
  ...
};