2016-05-29 69 views
0

我具有包括侧导航SAPUI5移除CSS类的聚合物品

<SideNavigation id="sideNavigation" expanded="false"> 
    <item> 
     <NavigationList expanded="false"> 
      <NavigationListItem text="Start" icon="sap-icon://employee" select="initChangeView" expanded="false"> 
      </NavigationListItem> 
      <NavigationListItem text="On Track" icon="sap-icon://building" select="initChangeView" expanded="false"> 
      </NavigationListItem> 
      <NavigationListItem text="Details" icon="sap-icon://employee" select="initChangeView" expanded="false"> 
      </NavigationListItem> 
      <NavigationListItem text="Comparison" icon="sap-icon://employee" select="initChangeView" expanded="false"> 
      </NavigationListItem> 
     </NavigationList> 
    </item> 

</SideNavigation> 

我要添加和删除自定义CSS类当一个项目的选择了XML视图片段。 我所试图做的是从每一个NavigationListItem删除类“selectedNavItem”并将其添加到选定的一个,但我得到的类型错误

无法读取的未定义的属性“removeStyleClass”

处理程序controller.js:

jQuery.sap.require("xxx.controller.NavigationBar"); 
[...] 
initChangeView: function(oEvent){ 
     setExpandedToFalse(this); 
     changeView(this, oEvent.getSource()); 
    }, 
[...] 

而且我NavigationBar.js:

function changeView(controller, source) { 
var items = source.getParent().getItems(); 
console.log(items); 
for(i = 0; i < items.length; i++) 
{ 
    items[i].getBindingContext().removeStyleClass("selectedNavItem"); 
} 
source.addStyleClass("selectedNavItem"); 
[...] 

谢谢!

回答

0

无论

items[i].getBindingContext().removeStyleClass("selectedNavItem");

也不

items[i].removeStyleClass("selectedNavItem");

会工作。

ContextBinding是一个特定的绑定对象 的情况下,它没有任何与做看起来ñ感觉控制的

另外,removeStyleClass不适用于NavigationListItem,因为removeStyleClass不是在它的任何祖先中可用;如果你看看它的层次结构,就像Element> Item> NavigationListItem

removeStyleClass仅用于扩展Control

+0

由于控制availble的,这就是我所需要的解释! – steinroe

0

由于您没有使用数据绑定来创建NavigationListItems,因此这些项目没有BindingContext。即使他们有一个,BindingContext也不会控制Control的样式。这样的事情应该工作你的情况:

items[i].removeStyleClass("selectedNavItem");