首页 \ 问答 \ TYPO3计算具有约束的对象并在流体模板中显示结果(TYPO3 count objects with constraint and display result in fluid template)

TYPO3计算具有约束的对象并在流体模板中显示结果(TYPO3 count objects with constraint and display result in fluid template)

我已经使用扩展构建器构建了一个扩展来处理objects ,一个object可以是“项目”或“项目”。

一个对象的字段status有4个选项,并用一个整数填充(3 =已售出)。

对象可以被签名为“项目”,在这种情况下,它具有用于isproject的布尔值1和具有相关对象作为项的字段项。

这一切都运行正常,我可以使用我的流体模板迭代项目,并使用<f:count>{object.items}</f:count>显示项目所属的项目数。

以同样的方式,我应该只显示已售商品的数量 ......
<f:count where="object.items.status == 3">{object.items}</f:count>这显然不起作用,只是为了呈现这个想法)

使用<f:debug>{object}</f:debug>我看到为所有项目定义的字段status ...
因为我不知道如何解决这个问题,所以我可能遗漏了一些重要的信息


I have build an extension with the extension builder that handles objects, an object can be an "item" or a "project".

An object has a field status which has 4 options, and is filled with an integer (3 = sold).

An object can be signed as a "project", in that case it has a boolean 1 for isproject and a field items with related objects as items.

this all works fine, I can iterate trough the projects with my fluid template and with <f:count>{object.items}</f:count> display the number of items appartaining to the project.

In the same fashion I should display the count of only the sold items ...
(<f:count where="object.items.status == 3">{object.items}</f:count> this obviously does not work, just to render the idea)

with <f:debug>{object}</f:debug> I see the field status defined for all items ...
since I have no idea how to approch this I might have left out some vital information


原文:https://stackoverflow.com/questions/41799848
更新时间:2022-12-22 06:12

最满意答案

您可以使用for和pattern匹配其返回值:

map = %{
  drop_off_lat: nil,
  drop_off_lng: "4.5",
  pick_up_lat: "6.5e2",
  pick_up_lng: nil,
}


[drop_off_lat, drop_off_lng, pick_up_lat, pick_up_lng] =
  for key <- [:drop_off_lat, :drop_off_lng, :pick_up_lat, :pick_up_lng] do
    case map[key] do
      nil -> 0.0
      value -> String.to_float(value)
    end
  end

IO.inspect {drop_off_lat, drop_off_lng, pick_up_lat, pick_up_lng}

输出:

{0.0, 4.5, 650.0, 0.0}

You can use for and pattern match its return value:

map = %{
  drop_off_lat: nil,
  drop_off_lng: "4.5",
  pick_up_lat: "6.5e2",
  pick_up_lng: nil,
}


[drop_off_lat, drop_off_lng, pick_up_lat, pick_up_lng] =
  for key <- [:drop_off_lat, :drop_off_lng, :pick_up_lat, :pick_up_lng] do
    case map[key] do
      nil -> 0.0
      value -> String.to_float(value)
    end
  end

IO.inspect {drop_off_lat, drop_off_lng, pick_up_lat, pick_up_lng}

Output:

{0.0, 4.5, 650.0, 0.0}

相关问答

更多
  • https://play.golang.org/p/JGZ7mN0-U- for k, v := range m { fmt.Printf("key[%s] value[%s]\n", k, v) } 要么 for k := range m { fmt.Printf("key[%s] value[%s]\n", k, m[k]) } Go语言规范for语句指定第一个值是键,第二个变量是值,但不一定存在。 https://play.golang.org/p/JGZ7mN0-U- for ...
  • 您正在寻找的结构只是一个功能: Key -> Value 。 你可以插入 (或者实际上替换)下面的值 insert :: (Key -> Value) -> Key -> Value -> (Key -> Value) insert f k v k' = if k == k' then v else f k' keys和values函数很容易实现(你只需要你的键类型是一个Enum )。 编译器可以警告你函数是否是部分函数(最终,你使用哪种数据结构,你不能阻止某人插入一个undefined值)。 The s ...
  • 这是预期的行为。 (doseq [x ... y ...])将遍历y中每个项目的每个项目。 相反,您应该遍历地图本身一次。 (seq some-map)将返回一个两项目向量的列表,一个用于映射中的每个键/值对。 (真的他们是clojure.lang.MapEntry ,但表现像2项目向量。) user> (seq {:foo 1 :bar 2}) ([:foo 1] [:bar 2]) doseq可以像任何其他的一样迭代这个seq。 像Clojure中的大多数功能与集合一起使用, doseq内部调用seq ...
  • 以下是使用Enum.reduce/3和Kernel.put_in/3的一种方法: state = %{ data: %{ "default" => %{ "someKeyword" => %{updated: 2} }, "baila" => %{ "morena" => %{updated: 2} } } } new_keyword = %{"someKeyword" => %{updated: 3, otherdata: 4}} ...
  • 那么,你可以使用Map> 。 我们使用了很多,因此使得我们自己的Map实现提供了两个键,并且在内部使用了map-of-map方法。 Well, you could use Map>. We use this a lot and thus made our own Map implementation that provides two keys and internally uses th ...
  • 我不知道任何这样做的功能。 还有必要定义您是否希望地图包含每个键或仅包含一些键。 我选择了每种情况,如果你想要某个版本,只需要替换every? 与some? 。 我的直接的,没有优化的版本是: (defn contains-many? [m & ks] (every? #(contains? m %) ks)) 已经通过以下测试: (deftest a-test (testing "Basic test cases" (let [m {:a 1 :b 1 :c 2}] (is ...
  • 只需存储两次值: Map map = new HashMap<>(); map.put(key1, someValue); map.put(key2, someValue); 事情是,关键是什么类型并不重要,所以使用允许两种键类型的通用绑定 - Object是好的。 请注意, Map#get()方法的参数类型无论如何都是Object ,所以从查找的角度来看,单独的映射没有价值(键的类型只与put()相关)。 Just store the value twice: Map
  • Guava的加载缓存可以解决您的超时和并发修改: https : //code.google.com/p/guava-libraries/wiki/CachesExplained将您的请求映射交换为LoadingCache,方法如下: LoadingCache requests = CacheBuilder.newBuilder() .maximumSize(1000) .expireAfterAccess(1, TimeUnit.MIN ...
  • 您可以使用for和pattern匹配其返回值: map = %{ drop_off_lat: nil, drop_off_lng: "4.5", pick_up_lat: "6.5e2", pick_up_lng: nil, } [drop_off_lat, drop_off_lng, pick_up_lat, pick_up_lng] = for key <- [:drop_off_lat, :drop_off_lng, :pick_up_lat, :pick_up_lng] do ...
  • 如果我理解你的问题,那么我会像往常一样实施你的方法 - public static boolean isUnique(Map input) { if (input == null || input.isEmpty()) { return true; } Set set = new HashSet(); for (V value : input.values()) { set.add(value); } return set.siz ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)