在艾考。如何在对话框中的自定义小部件内获取搜索查询参数?
In Aikau. How to get the search query parameters inside a custom widget in a dialog?
我正在使用 Alfresco 5。1.e
在搜索页面“/share/page/dp/ws/faceted-search”。我包含了一个按钮 "AlfDynamicPayloadButton"。
单击该按钮后,它会打开一个带有 "ALF_CREATE_DIALOG_REQUEST" 的对话框,其中包含我的自定义小部件。
我需要将当前搜索参数添加到该小部件中以创建特殊的可视化效果。
我在文件 "faceted-search.get.js" 中的代码:
var myWidget = {
name : "alfresco/buttons/AlfDynamicPayloadButton",
config : {
label : "My Button",
useHash : true,
hashDataMapping : {
"hashFragmentParameterName" : "buttonPayloadProperty"
},
publishPayloadSubscriptions : [ {
topic : "ALF_SEARCH_REQUEST"
}],
publishTopic : "ALF_CREATE_DIALOG_REQUEST",
publishPayloadType : "PROCESS",
publishPayloadModifiers : [ "processDataBindings" ],
publishPayload : {
dialogTitle : "My Title",
widgetsContent : [ {
name : "myPackage/Example",
config : {
width : 400,
height : 500
// other configurations
}
}]
}
}
};
var widget = widgetUtils.findObject(model.jsonModel.widgets, "id",
"FCTSRCH_TOP_MENU_BAR");
widget.config.widgets.push(myWidget);
我的小部件:
define(
[
"dojo/_base/declare",
"dijit/_WidgetBase",
"alfresco/core/Core",
"dijit/_TemplatedMixin",
"dojo/_base/lang",
"dojo/text!./html/Example.html"
],
function(declare, _Widget, Core, _Templated, lang, template) {
[ _Widget, Core, _Templated ],{
templateString : template,
i18nRequirements : [ {
i18nFile : "./i18n/Example.properties"
} ],
cssRequirements : [ {
cssFile : "./css/Example.css"
} ],
constructor : function example__constructor() {
// the widget is created each time the button is pressed
this.alfSubscribe("ALF_SEARCH_REQUEST",
lang.hitch(this, this.upgradeSearchParameter));
this.inherited(arguments);
},
upgradeSearchParameter:
function example__upgradeSearchParameter(args){
// this line never run
this.searchParameter = args;
}
});
});
到目前为止我已经尝试过:
- 在小部件内订阅 ALF_SEARCH_REQUEST。问题是发布主题时尚未创建小部件。
- Include "alfresco/services/SearchService" 依赖于我的小部件。我可以通过它访问查询的一些信息,例如 "sort"、"site"、"sortAscending" 等,但不能访问 "term".
- Include "alfresco/search/AlfSearchList" 依赖于我的小部件。我有 "searchTerm",但它总是空的 "".
在我的按钮中使用 "publishPayloadSubscriptions"。查询参数的所有信息都在对话框内,但不存在用该信息填充我的小部件的选项
publishPayloadSubscriptions : [ {
topic : "ALF_SEARCH_REQUEST"
}],
有什么方法可以在我的自定义小部件中获取最后一个查询的所有参数吗?
我认为您订阅 ALF_SEARCH_REQUEST
主题是正确的。如果您发现初始 ALF_SEARCH_REQUEST
主题(在加载页面时)在您的 AlfDynamicPayloadButton
注册其订阅之前发布,那么您可能需要考虑升级到更新的 Aikau 版本。
我们在 1.0.68 版本中修复了一个 issue 以确保在页面上所有小部件完成加载之前不会触发任何发布(这实际上是为了解决页面上有多个 Surf 组件的情况在分面搜索页面上不应该出现的页面!)。我们通过共享单例 PubQueue
来解决这个问题,该单例在创建所有小部件和服务之前不会发布任何出版物。
我想这可能取决于您在哪里创建 AlfDynamicPayloadButton
- 例如,如果它在搜索结果中,那么它将在 之后创建 ALF_SEARCH_REQUEST
主题已发布。
您是否检查过 DebugLog 以确保按钮中的订阅设置正确(例如,没有范围问题?)。
您是否已确认固定负载(带有硬编码数据)会导致显示您需要的对话框?您是否已验证该按钮未成功订阅主题,只是未按要求构建有效负载。
您能否也更新您的问题以显示您的 AlfDynamicPayloadButton
配置,因为这可能会帮助我找出问题所在。
好的,现在您已经添加了模型,我想我可以提供更好的答案...
您似乎刚刚复制了 JSDoc 中的示例。在您设置 hashDataMapping
配置的位置,您实际上可以重新配置它以获取搜索词。
每次搜索时,搜索文本都会在 URL 上设置为 searchTerm
哈希参数。这意味着将 useHash
配置为 true 您可以像这样配置 AlfDynamicPayloadButton:
{
name: "alfresco/buttons/AlfDynamicPayloadButton",
config : {
label : "My Button",
useHash : true,
hashDataMapping : {
searchTerm: "widgetsContent.0.config.searchTerm"
},
publishPayloadSubscriptions: [],
publishTopic: "ALF_CREATE_DIALOG_REQUEST",
publishPayload: {
dialogTitle: "My Title",
widgetsContent: [
{
name: "myPackage/Example",
config: {
width : 400,
height : 500
// other configurations
}
}
]
}
}
};
这里的关键是您将 searchTerm
URL 哈希值映射到 publishPayload
的 widgetsContent.0.config.searchTerm
属性。这意味着您的对话框中的自定义小部件将被分配上次使用的搜索词(分配给您的小部件可以引用的也称为 searchTerm
的属性)。
我正在使用 Alfresco 5。1.e
在搜索页面“/share/page/dp/ws/faceted-search”。我包含了一个按钮 "AlfDynamicPayloadButton"。
单击该按钮后,它会打开一个带有 "ALF_CREATE_DIALOG_REQUEST" 的对话框,其中包含我的自定义小部件。
我需要将当前搜索参数添加到该小部件中以创建特殊的可视化效果。
我在文件 "faceted-search.get.js" 中的代码:
var myWidget = {
name : "alfresco/buttons/AlfDynamicPayloadButton",
config : {
label : "My Button",
useHash : true,
hashDataMapping : {
"hashFragmentParameterName" : "buttonPayloadProperty"
},
publishPayloadSubscriptions : [ {
topic : "ALF_SEARCH_REQUEST"
}],
publishTopic : "ALF_CREATE_DIALOG_REQUEST",
publishPayloadType : "PROCESS",
publishPayloadModifiers : [ "processDataBindings" ],
publishPayload : {
dialogTitle : "My Title",
widgetsContent : [ {
name : "myPackage/Example",
config : {
width : 400,
height : 500
// other configurations
}
}]
}
}
};
var widget = widgetUtils.findObject(model.jsonModel.widgets, "id",
"FCTSRCH_TOP_MENU_BAR");
widget.config.widgets.push(myWidget);
我的小部件:
define(
[
"dojo/_base/declare",
"dijit/_WidgetBase",
"alfresco/core/Core",
"dijit/_TemplatedMixin",
"dojo/_base/lang",
"dojo/text!./html/Example.html"
],
function(declare, _Widget, Core, _Templated, lang, template) {
[ _Widget, Core, _Templated ],{
templateString : template,
i18nRequirements : [ {
i18nFile : "./i18n/Example.properties"
} ],
cssRequirements : [ {
cssFile : "./css/Example.css"
} ],
constructor : function example__constructor() {
// the widget is created each time the button is pressed
this.alfSubscribe("ALF_SEARCH_REQUEST",
lang.hitch(this, this.upgradeSearchParameter));
this.inherited(arguments);
},
upgradeSearchParameter:
function example__upgradeSearchParameter(args){
// this line never run
this.searchParameter = args;
}
});
});
到目前为止我已经尝试过:
- 在小部件内订阅 ALF_SEARCH_REQUEST。问题是发布主题时尚未创建小部件。
- Include "alfresco/services/SearchService" 依赖于我的小部件。我可以通过它访问查询的一些信息,例如 "sort"、"site"、"sortAscending" 等,但不能访问 "term".
- Include "alfresco/search/AlfSearchList" 依赖于我的小部件。我有 "searchTerm",但它总是空的 "".
在我的按钮中使用 "publishPayloadSubscriptions"。查询参数的所有信息都在对话框内,但不存在用该信息填充我的小部件的选项
publishPayloadSubscriptions : [ { topic : "ALF_SEARCH_REQUEST" }],
有什么方法可以在我的自定义小部件中获取最后一个查询的所有参数吗?
我认为您订阅 ALF_SEARCH_REQUEST
主题是正确的。如果您发现初始 ALF_SEARCH_REQUEST
主题(在加载页面时)在您的 AlfDynamicPayloadButton
注册其订阅之前发布,那么您可能需要考虑升级到更新的 Aikau 版本。
我们在 1.0.68 版本中修复了一个 issue 以确保在页面上所有小部件完成加载之前不会触发任何发布(这实际上是为了解决页面上有多个 Surf 组件的情况在分面搜索页面上不应该出现的页面!)。我们通过共享单例 PubQueue
来解决这个问题,该单例在创建所有小部件和服务之前不会发布任何出版物。
我想这可能取决于您在哪里创建 AlfDynamicPayloadButton
- 例如,如果它在搜索结果中,那么它将在 之后创建 ALF_SEARCH_REQUEST
主题已发布。
您是否检查过 DebugLog 以确保按钮中的订阅设置正确(例如,没有范围问题?)。
您是否已确认固定负载(带有硬编码数据)会导致显示您需要的对话框?您是否已验证该按钮未成功订阅主题,只是未按要求构建有效负载。
您能否也更新您的问题以显示您的 AlfDynamicPayloadButton
配置,因为这可能会帮助我找出问题所在。
好的,现在您已经添加了模型,我想我可以提供更好的答案...
您似乎刚刚复制了 JSDoc 中的示例。在您设置 hashDataMapping
配置的位置,您实际上可以重新配置它以获取搜索词。
每次搜索时,搜索文本都会在 URL 上设置为 searchTerm
哈希参数。这意味着将 useHash
配置为 true 您可以像这样配置 AlfDynamicPayloadButton:
{
name: "alfresco/buttons/AlfDynamicPayloadButton",
config : {
label : "My Button",
useHash : true,
hashDataMapping : {
searchTerm: "widgetsContent.0.config.searchTerm"
},
publishPayloadSubscriptions: [],
publishTopic: "ALF_CREATE_DIALOG_REQUEST",
publishPayload: {
dialogTitle: "My Title",
widgetsContent: [
{
name: "myPackage/Example",
config: {
width : 400,
height : 500
// other configurations
}
}
]
}
}
};
这里的关键是您将 searchTerm
URL 哈希值映射到 publishPayload
的 widgetsContent.0.config.searchTerm
属性。这意味着您的对话框中的自定义小部件将被分配上次使用的搜索词(分配给您的小部件可以引用的也称为 searchTerm
的属性)。