
Please pay attention to that the ManagedObjectModel still in Experimental API
Domain Model
Classes
sap.ui.define([
"sap/ui/base/ManagedObject"
], /**
* @param {typeof sap.ui.base.ManagedObject} ManagedObect
*/
function (ManagedObect) {
"use strict";
return ManagedObect.extend("sample.ui5.reactive.bean.Material", {
metadata: {
properties: {
uid: "string",
name: "string",
price: "int",
stock: "int",
status: "boolean"
},
aggregations: {},
events: {}
},
init: function () {},
setStock: function (value) {
this.setProperty("stock", value, true);
if (value && value > 0) {
this.setProperty("status", true);
} else {
this.setProperty("status", false);
}
}
});
});
sap.ui.define([
"sap/ui/base/ManagedObject"
], /**
* @param {typeof sap.ui.base.ManagedObject} ManagedObect
*/
function (ManagedObect) {
"use strict";
return ManagedObect.extend("sample.ui5.reactive.bean.StorageBin", {
metadata: {
properties: {
name: "string",
status:"boolean"
},
aggregations: {
materials:{
type:"sample.ui5.reactive.bean.Material",
multiple: true
}
},
events: {}
},
init: function () {},
getStatus:function(){
var aMaterials = this.getAggregation("materials");
var bStockZero = true;
$.each(aMaterials, function(index, item){
if(item.getStock() === 0){
bStockZero = false;
///exit
return false;
}
});
return bStockZero;
}
});
});
sap.ui.define([
"sap/ui/base/ManagedObject"
], /**
* @param {typeof sap.ui.base.ManagedObject} ManagedObect
*/
function (ManagedObect) {
"use strict";
return ManagedObect.extend("sample.ui5.reactive.bean.Warehouse", {
metadata: {
properties: {
name: "string"
},
aggregations: {
storageBins:{
type:"sample.ui5.reactive.bean.StorageBin",
multiple: true
}
},
events: {}
},
init: function () {}
});
});
{
"storageBins":[
{
"name":"Storage Bin 1",
"materials":[
{
"uuid":"11000211",
"name":"Material 1",
"price":100,
"stock":0
},
{
"uuid":"11000212",
"name":"Material 2",
"price":200,
"stock":5
}
]
},
{
"name":"Storage Bin 2",
"materials":[
{
"uuid":"11000211",
"name":"Material 3",
"price":45,
"stock":8
},
{
"uuid":"11000212",
"name":"Material 4",
"price":201570,
"stock":41
}
]
}
]
}
var oDataModelJson = this.getOwnerComponent().getModel("DataModelJson");
var oData = oDataModelJson.getData();
var oWarehouse = new Warehouse();
$.each(oData.storageBins, function(index, item){
var oStorageBin = new StorageBin();
oStorageBin.setName(item.name);
$.each(item.materials, function(indexM, itemM){
var oMaterial = new Material();
oMaterial.setUid(itemM.uuid);
oMaterial.setName(itemM.name);
oMaterial.setPrice(itemM.price);
oMaterial.setStock(itemM.stock);
oStorageBin.addMaterial(oMaterial);
});
oWarehouse.addStorageBin(oStorageBin);
});
this.getView().setModel(new ManagedObjectModel(oWarehouse), "DataModel");
<View controllerName="sample.ui5.reactive.controller.Main" xmlns:mvc="sap.ui.core.mvc" displayBlock="true" xmlns="sap.m">
<Page id="page" title="{i18n>title}">
<content>
<Table id="idProductsTable" inset="false" items="{
path: 'DataModel>/storageBins'
}" mode="SingleSelectMaster" itemPress=".onItemPress">
<columns>
<Column width="12em">
<Text text="Storage Bin" />
</Column>
<Column minScreenWidth="Desktop" demandPopin="true" hAlign="End">
<Text text="Status" />
</Column>
</columns>
<items>
<ColumnListItem vAlign="Middle" type="Active" highlight="{= ${DataModel>status}?'Success':'Error'}">
<cells>
<ObjectIdentifier title="{DataModel>name}" text="{DataModel>uid}" />
<Text text="{DataModel>status}" />
</cells>
</ColumnListItem>
</items>
</Table>
<HBox height="100px" ></HBox>
<Table id="idMaterialsTable" inset="false" items="{
path: 'DataModel>materials'
}">
<columns>
<Column width="12em">
<Text text="Material" />
</Column>
<Column minScreenWidth="Desktop" demandPopin="true" hAlign="End">
<Text text="Status" />
</Column>
<Column minScreenWidth="Desktop" demandPopin="true" hAlign="End">
<Text text="Stock" />
</Column>
</columns>
<items>
<ColumnListItem vAlign="Middle" highlight="{= ${DataModel>status}?'Success':'Error'}">
<cells>
<ObjectIdentifier title="{DataModel>name}" text="{DataModel>uid}" />
<Text text="{DataModel>status}" />
<StepInput
value="{DataModel>stock}"
min="0"
max="1000"
width="120px"
step="1"/>
</cells>
</ColumnListItem>
</items>
</Table>
</content>
</Page>
</View>
Application (1)
var oDataModelJson = this.getOwnerComponent().getModel("DataModelJson");
var oData = oDataModelJson.getData();
$.each(oData.storageBins, function(index, item){
Object.defineProperty(item, "status", {
get: function () {
var bStockZero = true;
$.each(item.materials, function(indexM, itemM){
if(itemM.stock === 0){
bStockZero = false;
///exit
return false;
}
});
return bStockZero;
}
});
$.each(item.materials, function(indexM, itemM){
Object.defineProperty(itemM, "status", {
get: function () {
return !!(itemM.stock && itemM.stock > 0);
}
});
});
});
this.getView().setModel(oDataModelJson, "DataModel");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
19 | |
18 | |
12 | |
9 | |
7 | |
7 | |
5 | |
5 | |
5 | |
5 |