您可以使用从TableSelcect对话框接收的绑定上下文来实现所需的功能。
但为了使绑定上下文正常工作,表单和表选择对话框都应该引用相同的模型。
以下是工作代码:
看法XML:
-
有一个按钮可触发“表格选择”对话框。
-
有一个表单。
<l:VerticalLayout class="sapUiContentPadding" width="100%">
<l:content>
<Button class="sapUiSmallMarginBottom" text="Show Table Select Dialog"
press="handleTableSelectDialogPress">
</Button>
<VBox class="sapUiSmallMargin">
<f:SimpleForm id="SimpleFormDisplay354">
<f:content>
<Label text="Supplier Name" />
<Text id="nameText" text="{SupplierName}" />
<Label text="Description" />
<Text text="{Description}" />
<Label text="ProductId" />
<Text text="{ProductId}" />
<Label text="Quantity" />
<Text id="countryText" text="{Quantity}" />
</f:content>
</f:SimpleForm>
</VBox>
</l:content>
</l:VerticalLayout>
控制器:
onInit: function () {
var oModel = new JSONModel(jQuery.sap.getModulePath("sap.ui.demo.mock", "/products.json"));
this.getView().setModel(oModel);
},
handleTableSelectDialogPress: function (oEvent) {
if (!this._oDialog) {
this._oDialog = sap.ui.xmlfragment("sap.m.sample.TableSelectDialog.Dialog", this);
}
this.getView().addDependent(this._oDialog);
this._oDialog.open();
},
handleClose: function (oEvent) {
var aContexts = oEvent.getParameter("selectedContexts");
if (aContexts && aContexts.length) {
this.byId('SimpleFormDisplay354').setBindingContext(aContexts[0]);
}
oEvent.getSource().getBinding("items").filter([]);
}
现在,我们还有一个选择对话框,点击任何我们称之为方法的项目:
handleClose
在里面
把手闭合
,我们获取单击的项目绑定上下文,然后告诉表单:嘿!请参考此上下文(模型中存在)。绑定上下文有一个路径,告诉表单从何处进行相对绑定。
请随时联系以获取更多信息。