使用智能表时是否可以自动选择第一行。我已经使用 ng-class 有条件地添加了 st-selected 类,该类突出显示了该行,但是当我选择另一行时,它不会取消选择第一行。
如果有任何帮助,我将不胜感激。
谢谢
最佳答案
我刚刚遇到了类似的问题,但想要有一个指定的默认选择,我通过分配咒骂和指令解决了这个问题。
(function(undefined) {
'use strict';
angular
.module('mymodule')
.directive('stDefaultSelection', function() {
return {
require: 'stTable',
restrict: 'A',
scope: {
selection: '=stDefaultSelection',
},
link: function link(scope, element, attrs, controller) {
scope.$watch('selection', function(newValue, oldValue) {
var selectionMode = 'single';
if (angular.isArray(newValue) && newValue.length > 1) {
selectionMode = 'multi';
}
if (angular.isArray(newValue)) {
newValue.forEach(function (row, index, array) {
controller.select(row, selectionMode);
});
} else {
controller.select(newValue, selectionMode);
}
});
}
};
});
})();
然后在你的html中:
<table st-table="myCtrl.data.records" st-safe-src="myCtrl.data.safeRecords" st-default-selection="myCtrl.defaultRecord">
设置数据后,然后设置您的默认记录,这可能会解决您的问题。
关于智能表 - 选择显示的第一行(angularjs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29193530/