过滤嵌套聚合绑定 [英] Filtering on Nested Aggregation Binding

查看:38
本文介绍了过滤嵌套聚合绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将过滤器应用于嵌套聚合绑定,但它似乎不起作用.这是 XML:

I want to be able to apply a filter to a nested aggregation binding, but it doesn't seem to work. Here is the XML:

<l:Grid id="test" defaultSpan="L6 M6 S6" content="{path : 'test>/', templateShareable:false}">
  <l:content>
    <VBox width="100%">
      <HBox height="100px" alignItems="Center" justifyContent="Start">
        <VBox alignItems="Center" width="25%">
          <core:Icon src="{test>icon}" width="100%" />
          <Text text="{test>text}" width="100%"/>
        </VBox>
        <VBox id="test" height="80px" items="{path: 'test>data/', templateShareable:false}">
          <Link text="{parts: [{ path: 'test>key'}, 
                               { path: 'test>value' }], 
                                 formatter : 'dostuff'}"/>
        </VBox>
      </HBox>
    </VBox>
  </l:content>
</l:Grid>

而我的JSON数据如下:

And my JSON data is as follows:

  {
  "results": [{
          "text": "object1",
          "icon": "icon1",
          "data": [{
              "value1": "foo",
              "value2": "bar"
          }, {
              "value1": "john",
              "value2": "smith"
          }]
      },

      {
          "text": "object2",
          "icon": "icon2",
          "data": [{
              "value1": "adam",
              "value2": "bobson"
          }, {
              "value1": "john",
              "value2": "smith"
          }, {
              "value1": "whatever",
              "value2": "work please"
          }]
      }
  ]

}

我希望能够过滤测试>/results/[n]/data/[n]/[value1 + value2] 并在该级别过滤网格.无论我尝试什么,它都只过滤 Grid 内容,因为我似乎无法获得 VBox 中测试"的绑定.

I want to be able to filter on test>/results/[n]/data/[n]/[value1 + value2] and have the gird filtered at that level. Whatever I try, it only filters on the Grid content because I can't seem to get the binding for the in VBox "test".

干杯,

詹姆斯

推荐答案

您是否尝试从 JS 动态过滤内容?还是直接从 XML 静态地?我假设您想从 JS 中执行此操作.

Are you trying to filter the content dynamically from JS? Or statically from the XML directly? I assume that you want to do it from JS.

带有 id 测试的 VBox 位于您已绑定其内容聚合的网格内.这意味着网格内的整个 VBox(包括测试 VBox)被视为网格内容聚合的模板(即使用我们的 JSON,您最终将拥有 VBox 的两个副本).

Your VBox with id test is inside a Grid whose content aggregation you have binded. This means that the whole VBox inside the grid (including the test VBox) is treated as a template for the content aggregation of the grid (i.e. with our JSON, you will end up having two copies of the VBox).

使用 this.byId("test") 显然不起作用,因为它会返回一个控件,该控件是网格的内容聚合模板的一部分.因此,为了能够过滤内部 VBox(因为根据模型的内容会有几个),您必须遍历网格的内容并将过滤应用于每个目标 VBox.类似的东西:

Using this.byId("test") will clearly not work, as it will return a control which is part of the Grid's content aggregation template. So be able to filter the inner VBoxes (because there will be several of them depending on the contents of the model), you have to iterate through the contents of the grid and apply the filtering to each of the target VBoxes. Something along the lines of:

this.byId("grid").getContent().forEach(function(oVbox) {
    // need to get the HBox and the second VBox from it.
    oVbox.getItems()[0].getItems()[1].getBinding("items").filter(...);
});

此外,Grid 和 VBox 具有相同的 ID,因此您的代码也会因此而失败.通常,您不需要为聚合模板或子项定义 ID.

Also, both the Grid and the VBox have the same IDs, so your code will fail because of that as well. Generally, you don't need to define an ID for an aggregation template or a child.

这篇关于过滤嵌套聚合绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆