请遵循此处的建议。
在您的场景中使用if绑定。您的代码应如下所示:
<div id="tabs" data-bind="dxTabs: { items: tabs, selectedIndex: selectedTab }"></div>
<div id="tabContent" style="height:300px;" >
<!-- ko if: !selectedTab() -->
<div>Tab1</div>
<!-- /ko -->
<!-- ko if: selectedTab() == 1 -->
<div data-bind="dxGallery: { dataSource: galleryData }"></div>
<!-- /ko -->
<!-- ko if: selectedTab() == 2 -->
<div>Tab3</div>
<!-- /ko -->
var viewModel = {
galleryData: [
"images/person1.png",
"images/person2.png",
"images/person3.png"
],
tabs: [
{ text: "user", icon: "user" },
{ text: "comment", icon: "comment" },
{ text: "find", icon: "find" },
],
selectedTab: ko.observable(0)
};