我在UI5中使用OData V4模型。我创建了一个带有一些扩展的绑定,现在尝试获取子实体的上下文。
这是我将实体绑定到某个元素的代码。结果,我得到一个对象为'SomeEntity'的数组和一个数组为'SomeOtherEntity'的属性。
#include <tuple>
#include <utility>
using namespace std;
template <size_t N, typename... Types>
struct Base
{
static constexpr size_t value = N;
};
template <typename Tuple, typename Indices>
struct Derived;
template <typename Tuple, size_t... Is>
struct Derived<Tuple, index_sequence<Is...>> : public Base<Is, std::tuple_element_t<Is,Tuple>... >...
{
// Works if following line is commented
using Base<Is, tuple_element_t<Is, Tuple>...>::Base...;
template<size_t M> bool check() const
{
return mValue == Base<M, tuple_element_t<Is, Tuple>...>::value;
}
size_t mValue;
};
template <typename... Types>
struct Test : public Derived<tuple<Types...>, make_index_sequence<sizeof...(Types)>>
{};
int main ()
{
using MyType = Test<int, float, float>;
MyType test;
return 0;
}
现在,我可以使用oPage.bindElement({
path: /SomeEntity(id),
parameters: {
$expand: {
SomeOtherEntity: {
$select: ['ID', 'name', 'sequence'],
$orderby: 'sequence'
}
}
}
});
获取绑定的上下文,并且可以从该对象执行oPage.getBindingContext()
和requestObject, setProperty, create
之类的方法。
我想要的是获取“ SomeOtherEntity”属性之一的上下文,以(例如)删除其中之一。 我不知道如何实现这一目标。有人有主意吗?
答案 0 :(得分:1)
您可以为 SomeOtherEntity 创建自己的ListBinding并过滤所需的集合。
(我不太确定,但是可能有必要在ListBinding上触发刷新以强制进行初始加载)
在加载数据(dataReceived-Event)之后,删除所有上下文。 每个Delete都会返回一个Promise,您可以继续Promise.all。
var oDataModel = this.getModel();
var aPromises= [];
var oListBinding = oDataModel.bindList("/SomeOtherEntity", undefined, undefined, new Filter("ID", FilterOperator.EQ, sIdToDelete), {
$$operationMode: OperationMode.Server
});
oListBinding.attachEventOnce("dataReceived", function (oEvent) {
var aContexts = oListBinding.getContexts();
aContexts.forEach(function (oContext) {
aPromises.push(oContext.delete("$auto"));
});
Promise.all(aPromises).then(function () {
/* Cleanup after Deletion
});
});