我决定合并https://lorenzofox3.github.io/smart-table-website/进入我的应用程序。网站上的示例工作正常,但是,当我开始集成时,我无法实现行选择功能。
演示站点和我之间的主要区别是我使用的是 Angular 1.5.8。我已经调试并识别了该片段,这让我产生了怀疑:
ng.module('smart-table')
.directive('stSelectRow', ['stConfig', function (stConfig) {
return {
restrict: 'A',
require: '^stTable',
scope: {
row: '=stSelectRow'
},
link: function (scope, element, attr, ctrl) {
var mode = attr.stSelectMode || stConfig.select.mode;
element.bind('click', function () {
scope.$apply(function () {
ctrl.select(scope.row, mode);
});
});
scope.$watch('row.isSelected', function (newValue) {
if (newValue === true) {
element.addClass(stConfig.select.selectedClass);
} else {
element.removeClass(stConfig.select.selectedClass);
}
});
}
};
}]);
函数link
接收scope
对象,其中row
未定义,因此select
函数会跳过并且什么也不做是在行上制作的。
我已经在笔上复制了这个问题:http://codepen.io/anon/pen/bwJqBw过滤和排序工作正常,只有行选择不行。
如何解决该问题以及原因是什么?范围绑定(bind)的语法是否已更改?根据文档,这似乎没问题,但作为一个 Angular 新手,我很难断言。
最佳答案
您需要在 st-select-row 中使用与您在 ng-repeat 中使用的相同引用,从您的代码笔中,您正在执行以下操作:
<tr st-select-row="row" st-select-mode="multiple" ng-repeat="customer in displayedCustomers">
你应该这样做:
<tr st-select-row="customer" st-select-mode="multiple" ng-repeat="customer in displayedCustomers">
关于javascript - 带有 Angular 1.5.8 的智能表 - 行选择不起作用 - 范围未填写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40264362/