如何从自定义控件的属性组中获取属性作为对象? [英] How can I get the properties from a property Group of a Custom Control as an Object?

查看:29
本文介绍了如何从自定义控件的属性组中获取属性作为对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发可在 Google 地图上显示标记的自定义控件.我有几个属性,如 "maptype" 、 "zoom" 等.在 Javascript 中很容易访问它们:我可以使用 #{javascript:compositeData.zoom} 来获取缩放属性.

I'm working on a Custom Control that displays markers on Google Maps. I have a couple of properties like "maptype" , "zoom", etc. It is easy to access them in Javascript: I can use #{javascript:compositeData.zoom} to get the value of the zoom property.

现在这是我的问题:我为每个标记使用一组属性.组名是marker",一个marker有6个属性:title"、layer"、infotext"、icon"、address"和animation".

Now this is my problem: I use a group of properties for each marker. The name of the group is "marker" and a marker has 6 properties: "title", "layer", "infotext", "icon", "address" and "animation".

如果我尝试使用

var markers = #{javascript:compositeData.marker}; 

我在 firebug 中遇到错误:

I'm getting an error in firebug:

missing : 在属性 id var 标记后 = [{layer=2,地址=奥尔登扎尔,动画=DROP,图标=/ogo_notes.png...

missing : after property id var markers = [{layer=2, address=Oldenzaal, animation=DROP, icon=/ogo_notes.png...

箭头指向第一个 = 层和 2 之间(我不允许在 stackoverflow 中放入图片)

an arrow is pointing to the first = between layer and 2 (I am not allowed to put in an image in stackoverflow)

如果我使用

var markers = #{javascript:'"' + compositeData.marker + '"'};

markers 是一个对象,但每个对象都包含一个字符串,其中包含标记的所有属性.

markers is an Object, but each Object contains a string with all the propperties of the marker.

我知道我可以做一些编码来创建每个字符串的对象,但如果不是所有属性都需要,这并不容易.如果不需要属性,则它不会显示在字符串中.

I know I can do some coding to make an object of each string, but this is not easy if not all propperties are required. If a propperty is not required than it will not show up in the string.

我想必须有一种更简单的方法来将每个标记作为一个对象,这样我就可以使用如下代码获取图标的值:

I guess that there must be a more easy way to get each marker as an object so I can get the value of the icon with code like:

var icon = marker.icon

我该怎么做?

推荐答案

可以使用compositeData.marker.icon来获取组内的属性icon标记.如果您已为该组选中允许多个实例",则要获取属性,您必须:

You can use compositeData.marker.icon to get the property icon inside the group marker. If you have checked "Allow multiple instances" for the group then to get the properties you will have to go:

compositeData.marker[0].icon
compositeData.marker[1].icon

等等...

2012 年 4 月 26 日更新(Naveen)

要将它与客户端 javascript 一起使用,您可以尝试将值放入这样的隐藏输入字段中:

To use it with client side javascript you can try to put the value in a hidden input field like this:

<xp:inputHidden id="hdnIcon">
        <xp:this.defaultValue><![CDATA[#{javascript:var value = new Array();
for (var i=0 ; i<compositeData.marker.length ; i++) {
    value.push(compositeData.marker[i].icon);
}
return @Implode(value, ",");}]]></xp:this.defaultValue>
</xp:inputHidden>

这个隐藏输入字段的值可以通过客户端javascript读取,如下所示:

The value of this hidden input field can be read through client-side javascript like this:

var value = document.getElementById("#{id:hdnIcon}").value.split(",");
for (var i=0 ; i<value.length ; i++) {
    <YOUR CODE>
}

另一种方法是将 compositeData.marker 及其内容转换为 JSON 字符串,然后在其上运行客户端 javascript.

Another way to do this can be to convert compositeData.marker and its contents to a JSON string and then run the client-side javascript on it.

这篇关于如何从自定义控件的属性组中获取属性作为对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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