[英]How to clear Lookup field in MS Dynamics CRM 4.0 using JavaScript
I'm trying clear the value of a lookup field via Javascript. 我正在尝试通过Javascript清除查找字段的值。 I've tried this:
我试过这个:
crmForm.all.new_mylookupfield.DataValue = null;
But that isn't working. 但这不起作用。 I inspected the DataValue of the lookup when it was in fact cleared and it returned a null.
我检查了查找的DataValue,当它实际上被清除并返回null。
alert(document.getElementById("new_mylookupfield").DataValue == null); // true
I'm must be missing something here.... 我必须在这里遗漏一些东西....
Thanks for the help! 谢谢您的帮助!
UPDATE: I finally got around to testing some of the suggestions. 更新:我终于开始测试一些建议了。 I'm not sure what I was doing wrong initially, but both of these methods work to clear a lookup via JavaScript:
我不确定我最初做错了什么,但这两种方法都可以通过JavaScript清除查找:
crmForm.all.new_mylookupfield.DataValue = null;
crmForm.all.new_mylookupfield.DataValue = [];
Lookup controls have a specific type of object for their DataValue. 查找控件的DataValue具有特定类型的对象。 It's an array of objects that look like this:
它是一个对象数组,如下所示:
{
id: /* item id */,
typename: /* entity type name */,
name: /* text to display in link */
}
If you want to remove all values from the lookup, you can set it to null, but it's better to just set it to an empty array. 如果要从查找中删除所有值, 可以将其设置为null,但最好将其设置为空数组。
If you assign the value, but it doesn't seem to change anything, then you are probably not typing the correct id for the attribute. 如果您指定了值,但似乎没有更改任何内容,那么您可能没有为该属性键入正确的ID。 For example: If I have an entity with a lookup attribute of
sneakers_brokerid
, then I need to assign that value like so: 例如:如果我有一个查找属性为
sneakers_brokerid
的实体,那么我需要像这样分配该值:
crmForm.all.sneakers_brokerid.DataValue = [];
我不记得必须这样做,但你尝试将值设置为一个长度为零的新Array()吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.