Anguilla - 从弹出窗口更新字段的值? [英] Anguilla - Updating a field's value from a popup?

查看:21
本文介绍了Anguilla - 从弹出窗口更新字段的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当编辑器尝试使用某些值(在本例中为过去的日期字段)保存组件时,就会出现一个模态弹出窗口.

I have a modal popup that appears whenever an editor tries to save a component with some values (a date field in the past in this case).

在这个弹出窗口中,我向编辑器展示了一些选项(非常类似于默认的打开共享项目"对话框)和一个确定/取消按钮组合.在取消我触发取消"事件和编辑器返回编辑屏幕,一切都很好.在确定"上我想更改该字段的值以匹配编辑器选择的任何内容,然后保存.

In this popup I show the editor a few options (very similar to the default "Open Shared Item" dialog) and an OK/Cancel button combo. On Cancel I fire the "cancel" event and the editor goes back to the editing screen, all good here. On "OK" I want to change the value of the field to match whatever the editor selected, then save.

我尝试对 FieldBuilder 和 其他主题 中提到的示例 Boris 使用一种方法,但我无法理解从我的弹出对话框到该字段.

I tried to use an approach with FieldBuilder and the sample Boris mentioned on this other topic but I can't get to the field from my popup dialog.

关于如何从模式弹出窗口修改项目(也可以是页面)的 xml 的任何建议?

Any suggestions on how I can go and modify the xml of the item (could be also a page) from a modal popup?

getControlForFieldName 中使用的代码

Code used in getControlForFieldName

function getControlForFieldName(name) {
    var fieldBuilder = $display.getView().properties.controls.fieldBuilder;
    var fieldsContainer = fieldBuilder.properties.input;
    var fieldsNode = fieldsContainer.getElement();
    var fieldContainer = $dom.getFirstElementChild(fieldsNode);
    while (fieldContainer) {
        var labelNode = $dom.getFirstElementChild(fieldContainer);
        var fieldNode = $dom.getNextElementSibling(labelNode);
        var control = fieldNode.control;
        if (control.getFieldName() == name) {
            return control;
        }
        fieldContainer = $dom.getNextElementSibling(fieldContainer);
    }
}

编辑#2

在 Frank 的建议下,以及 Jaime & 的一些帮助之后弗兰克离线,我让它工作如下:

After Frank's advice, and some help from Jaime & Frank offline, I got it to work as follows:

  1. 弹出窗口是从命令扩展中调用的(在我的例子中是保存并关闭)
  2. command.js 指定了一个在提交"时调用的事件处理程序.(==确定被按下)

$evt.addEventHandler(p.dialogPopup, "submit", 
    this.getDelegate(this._onPopupSubmit));

在我的弹出窗口中,我将所选项目(它是一个关键字 ID)传递给事件处理程序:

In my popup I am passing the selected item (it's a keyword ID) to the event handler:

this.fireEvent("submit", { id: select.options[select.selectedIndex].value });

现在回到事件处理程序 _onPopupSubmit(e) 我只是读取 e.data.id,加载这个关键字,获取像 ID & 这样的属性.标题,并使用 item.setMetadata(具有更新值的新元数据")更新项目的元数据.

and now back in the event handler _onPopupSubmit(e) I just read e.data.id, load this keyword, get properties like ID & Title, and update the metadata of the item using item.setMetadata("new metadata with updated values").

简单:)

推荐答案

您的代码在弹出窗口中运行,因此您对全局变量所做的任何引用都将从弹出窗口中获取.

Your code runs in a popup, so any references you make to global variables will be taken from the popup window.

所以当你得到 fieldBuilder 时:

So when you get the fieldBuilder:

var fieldBuilder = $display.getView().properties.controls.fieldBuilder;

$display 是对全局变量的引用.所以这实际上是在弹出窗口(没有)中查找 FieldBuilder.

$display is a reference to a global variable. So this actually looks for the FieldBuilder in the popup window (which doesn't have one).

获取Component窗口的FieldBuilder,可以从opener获取:

To get the FieldBuilder of the Component window, you can get it from the opener:

var fieldBuilder = opener.$display.getView().properties.controls.fieldBuilder;

您可能需要考虑将更新后的值实际传递给回调函数或使用(自定义)事件,因为这会减少您的弹出窗口对 opener. 技巧的依赖.

You might want to consider actually passing the updated value to either a callback function or with a (custom) event though, since that makes your popup less dependent on opener. trick.

这篇关于Anguilla - 从弹出窗口更新字段的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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