У меня есть основное/подробное приложение для каталогов и файлов. В моей службе OData у меня есть свойство навигации, которое ведет от каталога к набору файлов. У меня есть список в подробном представлении для файлов каталога. Но у меня возникли проблемы связывания его свойства навигации службы ODataКак связать список с навигационным свойством
<mvc:View xmlns:core="sap.ui.core" xmlns:f="sap.ui.layout.form" xmlns:l="sap.ui.layout" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" controllerName="FileUtility.view.Detail">
<Page id="detailPage" navButtonPress="onNavBack" showNavButton="{device>/isPhone}" title="Files">
<content>
<ObjectHeader iconActive="false" id="detailHeader" introActive="false" number="" numberUnit="" title="" titleActive="false">
<attributes id="detailAttributes">
<ObjectAttribute active="false" id="attribute" text="{i18n>detailText}"/>
</attributes>
<firstStatus id="detailStatus">
<ObjectStatus id="status" text=""/>
</firstStatus>
</ObjectHeader>
<List id="__list0" noDataText="Drop list items here" items="{path :'DirectorySet>/FileSet'}">
<items>
<ObjectListItem counter="0" id="__item5" showMarkers="false" title="{Name}" type="Active">
</ObjectListItem>
</items>
<core:ExtensionPoint name="extDetail"/>
</List>
</content>
<footer id="detailFooter">
<Toolbar id="detailToolbar">
<content>
<ToolbarSpacer id="toolbarSpacer"/>
<Button icon="sap-icon://action" id="actionButton" press="openActionSheet"/>
</content>
</Toolbar>
</footer>
</Page>
</mvc:View>
Путь пунктов является имя набора источника объект. Не знаете, где именно должно было получить это имя. Часть FileSet - это свойство навигации. Я смущен, как сопоставить его в представлении.
EDIT: я удалил «item = {}» из тега List и попытался связать его в файле Detail.js.
sap.ui.core.mvc.Controller.extend("FileUtility.view.Detail", {
onInit : function() {
this.oInitialLoadFinishedDeferred = jQuery.Deferred();
if(sap.ui.Device.system.phone) {
//Do not wait for the master when in mobile phone resolution
this.oInitialLoadFinishedDeferred.resolve();
} else {
this.getView().setBusy(true);
var oEventBus = this.getEventBus();
oEventBus.subscribe("Component", "MetadataFailed", this.onMetadataFailed, this);
oEventBus.subscribe("Master", "InitialLoadFinished", this.onMasterLoaded, this);
}
this.getRouter().attachRouteMatched(this.onRouteMatched, this);
},
onMasterLoaded : function (sChannel, sEvent) {
this.getView().setBusy(false);
this.oInitialLoadFinishedDeferred.resolve();
},
onMetadataFailed : function(){
this.getView().setBusy(false);
this.oInitialLoadFinishedDeferred.resolve();
this.showEmptyView();
},
onRouteMatched : function(oEvent) {
var oParameters = oEvent.getParameters();
var oView = this.getView();
var sEntityPath = "/" + oParameters.arguments.entity;
var oContext = new sap.ui.model.Binding(this.getView().getModel(), sEntityPath + '/FileSet');
this.getView().setBindingContext(oContext);
//var oList = oView.byId("__list0");
//oList.bindItems(sEntityPath + '/FileSet',sap.ui.getCore().byId(this.getView().byId('__item5').getId()));
//sap.ui.getCore().byId(this.getView().byId('__list0').getId()).bindItems(sEntityPath + '/FileSet',sap.ui.getCore().byId(this.getView().byId('__item5').getId()));
//this.bindView(sEntityPath);
jQuery.when(this.oInitialLoadFinishedDeferred).then(jQuery.proxy(function() {
// When navigating in the Detail page, update the binding context
if (oParameters.name !== "detail") {
return;
}
var oIconTabBar = oView.byId("idIconTabBar");
oIconTabBar.getItems().forEach(function(oItem) {
if(oItem.getKey() !== "selfInfo"){
oItem.bindElement(oItem.getKey());
}
});
//var oList = oView.byId("__list0");
//oList.bindItems(sEntityPath + '/FileSet');
//sap.ui.getCore().byId(this.getView().byId('__list0').getId()).bindItems(sEntityPath + '/FileSet',sap.ui.getCore().byId(this.getView().byId('__item0').getId()));
// Specify the tab being focused
var sTabKey = oParameters.arguments.tab;
this.getEventBus().publish("Detail", "TabChanged", { sTabKey : sTabKey });
if (oIconTabBar.getSelectedKey() !== sTabKey) {
oIconTabBar.setSelectedKey(sTabKey);
}
}, this));
},
bindView : function (sEntityPath) {
var oView = this.getView();
oView.bindElement(sEntityPath);
//Check if the data is already on the client
if(!oView.getModel().getData(sEntityPath)) {
// Check that the entity specified was found.
oView.getElementBinding().attachEventOnce("dataReceived", jQuery.proxy(function() {
var oData = oView.getModel().getData(sEntityPath);
if (!oData) {
this.showEmptyView();
this.fireDetailNotFound();
} else {
this.fireDetailChanged(sEntityPath);
}
}, this));
} else {
this.fireDetailChanged(sEntityPath);
}
},
showEmptyView : function() {
this.getRouter().myNavToWithoutHash({
currentView : this.getView(),
targetViewName : "FileUtility.view.NotFound",
targetViewType : "XML"
});
},
fireDetailChanged : function (sEntityPath) {
this.getEventBus().publish("Detail", "Changed", { sEntityPath : sEntityPath });
},
fireDetailNotFound : function() {
this.getEventBus().publish("Detail", "NotFound");
},
onNavBack : function() {
// This is only relevant when running on phone devices
this.getRouter().myNavBack("main");
},
onDetailSelect : function(oEvent) {
sap.ui.core.UIComponent.getRouterFor(this).navTo("detail",{
entity : oEvent.getSource().getBindingContext().getPath().slice(1),
tab: oEvent.getParameter("selectedKey")
}, true);
},
openActionSheet: function() {
if (!this._oActionSheet) {
this._oActionSheet = new sap.m.ActionSheet({
buttons: new sap.ushell.ui.footerbar.AddBookmarkButton()
});
this._oActionSheet.setShowCancelButton(true);
this._oActionSheet.setPlacement(sap.m.PlacementType.Top);
}
this._oActionSheet.openBy(this.getView().byId("actionButton"));
},
getEventBus : function() {
return sap.ui.getCore().getEventBus();
},
getRouter : function() {
return sap.ui.core.UIComponent.getRouterFor(this);
},
onExit : function(oEvent){
var oEventBus = this.getEventBus();
oEventBus.unsubscribe("Master", "InitialLoadFinished", this.onMasterLoaded, this);
oEventBus.unsubscribe("Component", "MetadataFailed", this.onMetadataFailed, this);
if (this._oActionSheet) {
this._oActionSheet.destroy();
this._oActionSheet = null;
}
}
});
Я добавил код привязки к методу onRouteMatched.
EDIT 2:
Мои связывания в контроллере:
var oList = oView.byId("__list0");
var oTemplate = this.getView().byId('__item5');
oList.bindItems(sEntityPath + '/FileSet',sap.ui.getCore().byId(oTemplate.getId()));
Я не получаю никаких данных обратно, но путь в SAPUI5 отладчик правильно, несмотря на отмеченные как «недопустимый»
EDIT 3
Я получил его, используя этот код в функции onRouteMatched
var oList = oView.byId("__list0");
var oTemplate = oView.byId('__item5');
oTemplate.bindProperty('title', 'Name');
oList.bindItems(sEntityPath + '/FileSet', sap.ui.getCore().byId(oTemplate.getId()));
Спасибо за ответ. Я попробовал ваше предложение, но оно не сработало. Я отредактирую сообщение и добавлю файл Detail.js. – TheGreenToaster
У вас все еще есть связанный только основной объект, но не с ключом. Так что скажем, что Entity - это папки и ключ одного из них - Folder1. Вам необходимо привязать подробное представление как папку ('Folder1'). Поскольку FileSet требует одно значение, на котором можно запустить навигацию. Пропустите также путь привязки. Вероятно, поможет jsbin или главный контроллер/код просмотра. – Veeraraghavan
Если я устанавливаю точку останова на нем, значение sEntityPath является сущностью с ключом. Но когда я смотрю на отладчик SAPUI5, он не отобразит привязку для списка – TheGreenToaster