$(this).tabs('options').lastTabIndex = undefine、
时间: 2024-01-30 20:02:38 浏览: 30
如果在使用`$(this).tabs('options').lastTabIndex`代码时出现`undefined`的错误,一般是由于`lastTabIndex`属性没有被成功设置或者被清空了。
可以尝试在tab组件初始化时手动设置`lastTabIndex`属性。例如,在初始化时设置默认选中的tab为第一个tab,并将`lastTabIndex`属性设置为0,代码如下:
```javascript
$('#tabs').tabs({
// 设置默认选中的tab为第一个tab
selected: 0,
// 设置lastTabIndex为0
onLoad: function(panel) {
$(this).tabs('options').lastTabIndex = 0;
},
onSelect: function(title, index) {
// 获取之前被选中的tab
var lastTabIndex = $(this).tabs('options').lastTabIndex;
var lastTab = $(this).tabs('getTab', lastTabIndex);
// 获取之前被选中的tab内的datagrid组件
var lastDatagrid = lastTab.find('.datagrid-f');
// 清除选中行
lastDatagrid.datagrid('clearSelections');
// 更新lastTabIndex
$(this).tabs('options').lastTabIndex = index;
}
});
```
在`onLoad`事件中设置`lastTabIndex`为0,在`onSelect`事件中更新`lastTabIndex`为当前选中的tab的索引。这样在切换tab时就可以正确地清除之前的`datagrid`的选中了。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)