更新:
我想在 BackOffice 的内容选项卡上获取在单击保存按钮后和以编程方式保存更改之前已更改的节点属性值。
节点可以包含许多属性。单击保存按钮时,我想首先获取节点属性的新更改值。我认为 Umbraco 应该有 API 来在服务器端获取这些。
任何想法将不胜感激。
您希望连接到 IApplicationEventHandler 类中的 Document.BeforeSave 方法。像这样(假设您要将正文文本从"苹果"更改为"橙色"):
using umbraco.cms.businesslogic.web;
using Umbraco.Core;
using Umbraco.Web;
namespace ClassLibrary1
{
public class Class1 : IApplicationEventHandler
{
public void OnApplicationStarted(UmbracoApplication httpApplication, ApplicationContext applicationContext)
{
Document.BeforeSave += new Document.SaveEventHandler(Document_BeforeSave);
Document.AfterSave += new Document.SaveEventHandler(Document_AfterSave);
}
void Document_BeforeSave(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
{
// your code goes here!
sender.getProperty("bodyText").Value // returns apple
}
void Document_AfterSave(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
{
// your code goes here!
sender.getProperty("bodyText").Value // returns orange
}
public void OnApplicationStarting(UmbracoApplication httpApplication, ApplicationContext applicationContext)
{
// unused
}
public void OnApplicationInitialized(UmbracoApplication httpApplication, ApplicationContext applicationContext)
{
// unused
}
}
}
我在 Umbraco 4.11 中对此进行了测试
。干杯
乔纳森
你可以做的是使用jquery事件处理程序,它针对你想要检查更改的umbraco管理中的字段。 此示例的工作原理是查找要监视的 umbraco 字段的标签,然后添加一个 jquery 事件处理程序,该处理程序将在更改与标签的同级字段时触发 - 此示例将适用于对每个节点的"属性"选项卡上的"名称"字段的任何更改。 不同的字段类型会以不同的方式保存值,因此 $(this).val() 通常应该适用于大多数 - 但不是所有字段类型。
把它放到\umbraco\editcontent的末尾.aspx
<script type="text/javascript">
$(document).ready(function () {
$("div.propertyItemheader:contains('Name') + div.propertyItemContent").keyup(function () {
alert("field changed");
});
});
</script>