在组件编辑器中获取字段的 _current_ 值?(Tridion 2011 SP1) [英] Get a field's _current_ value in Component Editor? (Tridion 2011 SP1)

查看:20
本文介绍了在组件编辑器中获取字段的 _current_ 值?(Tridion 2011 SP1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写保存"命令的扩展,基本上我想验证某些字段并显示一个弹出窗口,允许编辑器根据当前日期、版本号和其他一些选择给定的关键字或其他值属性.

我以为我取得了不错的进展,直到我最终发现 $display.getItem() 返回的是存储在 CM 中的项目,而不是编辑器可能已更改的当前值.

是否有内置方法可以让我获得这些信息?还是我需要解析 DOM 才能弄清楚?

这是我目前拥有的代码

var item = $display.getItem();if (item.getItemType() == "tcm:16") {如果(item.getSchema().getStaticTitle()==测试模式"){var content = $xml.getNewXmlDocument(item.getContent());var fieldXml = $xml.getInnerText(content, "///*[local-name()='NewField']");警报(fieldXml);}}

它正在工作 - 我得到了NewField"的值 - 但这是项目加载时具有的值,而不是当前值.>

有趣的是,item.getTitle() 显示了 Title 字段的当前值,所以我希望也有一种方法可以为自定义字段实现这一点.

解决方案

我不知道这是否是正确的方法,但是您可以在项目上触发collectdata"事件 - 这将更新它的数据到目前为止在编辑屏幕上输入的内容.

var item = $display.getView().getItem();item.fireEvent("收集数据");$log.message(item.getXml());

I'm writing an extension to the "Save" Command, where basically I want to validate certain fields and present a popup allowing the editor to select a given keyword or other values based on current date, a Release # and some other attributes.

I thought I was doing good progress until I finally figured out that $display.getItem() is returning the item as is stored in CM, not the current values that the editor may have changed.

Is there a built-in method to get me this information? Or do I need to parse the DOM to figure it out?

This is the code I currently have

var item = $display.getItem();
if (item.getItemType() == "tcm:16") {
   if (item.getSchema().getStaticTitle() == "Test Schema") {
      var content = $xml.getNewXmlDocument(item.getContent());
      var fieldXml = $xml.getInnerText(content, "//*[local-name()='NewField']");
      alert(fieldXml);
   }
}

It is working - I get the value of "NewField" - but this is the value the item had when it was loaded, not the current value.

Interestingly, item.getTitle() shows the current value of the Title field, so I hope there may be a way to achieve this for custom fields too.

解决方案

I don't know if this is the proper way to do it, but you could fire the "collectdata" event on the item - which will update it's data with what has been entered on the editing screen so far.

var item = $display.getView().getItem();
item.fireEvent("collectdata");
$log.message(item.getXml());

这篇关于在组件编辑器中获取字段的 _current_ 值?(Tridion 2011 SP1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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