简体   繁体   English

SugarCRM 7:在事件上下文之外调用BaseFilterLayout.applyFilter()方法

[英]SugarCRM 7: Call BaseFilterLayout.applyFilter() method outside event context

I'm working on a customization for Sugar Professional 7.2.x that pushes a filter from an auxiliary script into the filter function for the list view page. 我正在为Sugar Professional 7.2.x进行定制,该定制将过滤器从辅助脚本推送到列表视图页面的过滤器功能中。 By setting a breakpoint inside the applyFilter function and exporting the function itself as a member of the global object, I can then call the function from my script and execute a temporary filter accordingly. 通过在applyFilter函数内设置一个断点并将函数本身导出为全局对象的成员,我可以从脚本中调用该函数并相应地执行一个临时过滤器。 So I know I have the correct syntax for execution, eg: 所以我知道我有正确的执行语法,例如:

window.exportedApplyFilter(null, {name:"Mr. Rogers"});

The hangup is that I can't get that applyFilter function in any other way, eg 挂断是我无法以任何其他方式获得applyFilter函数,例如

App.view.layout.someMagicObject.applyFilter(...);

Is there a way to access that function from another script? 有没有办法从另一个脚本访问该功能?

Thanks to the Sugar team, I have an answer to my question. 多亏了Sugar团队,我对我的问题有了答案。 The solution is to pry in through the controller.layout object tree: 解决方案是通过controller.layout对象树插入:

App.controller.layout.getComponent('sidebar').getComponent('main-pane')

This allows one to drill down to any Sidecar UI component and access the controller functions associated therewith. 这允许人们向下钻取到任何Sidecar UI组件并访问与其关联的控制器功能。 Perhaps not as elegant as other solutions, but it's readable. 也许不如其他解决方案那么优雅,但是它是可读的。

If I wanted to take this further, I might write a short function to recurse through the subtree and look for the element with the correct CID number, then return the full path to it. 如果我想进一步介绍它,我可能会编写一个简短的函数来遍历子树并查找具有正确CID号的元素,然后返回其完整路径。 CID numbers are progressive and advance depth-first, so the search would be pretty fast. CID编号​​是渐进式的,并且是深度优先的,因此搜索将非常快。 But a hand search in the browser dev console only took minutes. 但是在浏览器开发者控制台中进行手动搜索仅需几分钟。 Once that's found, accessing it again is a matter of a chain of getComponent(...) calls. 一旦找到,就可以通过一系列getComponent(...)调用来再次访问它。 The final return from the chain should be the element wanted (filter control, in my case) and should have the desired method as well. 链的最终返回应该是所需的元素(在我的情况下为过滤器控件),并且还应该具有所需的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM