我想访问[PATH_TO_SOME_OTHER_MODEL]
值。这样,当视图加载时,可以通过oData V4调用本身过滤TEAMS
<Select id="TeamSelect" change="onTeamSelect" autoAdjustWidth="true"
items="{
path : '/TEAMS',
parameters : {
$filter : 'Name startswith \'[PATH_TO_SOME_OTHER_MODEL]\''
}
}" >
<core:Item key="{Team_Id}" text="{Name}"/>
</Select>
从另一个模型获取值的正确语法是什么?
答案 0 :(得分:1)
您不能直接在XML中进行操作。加载两个模型后,您需要创建并添加过滤器。
这是一个片段
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta charset="utf-8">
<title>MVC with XmlView</title>
<!-- Load UI5, select "blue crystal" theme and the "sap.m" control library -->
<script id='sap-ui-bootstrap' src='https://sapui5.hana.ondemand.com/resources/sap-ui-core.js' data-sap-ui-theme='sap_belize_plus' data-sap-ui-libs='sap.m' data-sap-ui-xx-bindingSyntax='complex'></script>
<!-- DEFINE RE-USE COMPONENTS - NORMALLY DONE IN SEPARATE FILES -->
<script id="view1" type="sapui5/xmlview">
<mvc:View xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" controllerName="my.own.controller">
<Select modelContextChange="onChange" id="mySelect" items="{ path: 'model1>/Names'}">
<core:Item key="{model1>Id}" text="{model1>Name}" />
</Select>
<Button text="Disable Filter" press="removeFilter"></Button>
<Button text="Enable Filter" press="addFilter"></Button>
</mvc:View>
</script>
<script>
// define a new (simple) Controller type
sap.ui.controller("my.own.controller", {
onAfterRendering: function() {
this.addFilter();
},
addFilter: function() {
var sFilterQuery = this.getView().getModel("model2").getProperty("/filterQuery");
var oFilter = new sap.ui.model.Filter("Name", sap.ui.model.FilterOperator.StartsWith, sFilterQuery);
this.getView().byId("mySelect").getBinding("items").filter(oFilter);
},
removeFilter: function() {
this.getView().byId("mySelect").getBinding("items").filter();
}
});
/*** THIS IS THE "APPLICATION" CODE ***/
// create some dummy JSON data
var data1 = {
Names: [{
"Id": 1,
"Name": "John",
},
{
"Id": 1,
"Name": "Mark",
},
{
"Id": 1,
"Name": "Liz",
},
{
"Id": 1,
"Name": "Jane",
}
]
};
var oJSONModel = new sap.ui.model.json.JSONModel();
oJSONModel.setData(data1);
//create a second model
var data2 = {
filterQuery: "J"
};
var oJSONModel2 = new sap.ui.model.json.JSONModel();
oJSONModel2.setData(data2);
// instantiate the View
var myView = sap.ui.xmlview({
viewContent: jQuery('#view1').html()
}); // accessing the HTML inside the script tag above
myView.setModel(oJSONModel, "model1");
myView.setModel(oJSONModel2, "model2");
// put the View onto the screen
myView.placeAt('content');
</script>
</head>
<body id='content' class='sapUiBody'>
</body>
</html>