Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从文本中删除html标记并将其存储在EL中?_Javascript_Html_Json_Atg_Atg Dynamo - Fatal编程技术网

Javascript 如何从文本中删除html标记并将其存储在EL中?

Javascript 如何从文本中删除html标记并将其存储在EL中?,javascript,html,json,atg,atg-dynamo,Javascript,Html,Json,Atg,Atg Dynamo,我正在使用atg dsp:valueof标记获取数据,其'valueishtml'属性设置为true。我需要通过EL将检索到的数据(即没有任何html标记)传递给json变量。有人能告诉我怎么做吗。下面是我需要做的一个例子。请注意这不是一个代码 var mydatawithouthtml = <dsp:valueof param="product.data" valueishtml="true"/> <json:property name="data" value="${my

我正在使用atg dsp:valueof标记获取数据,其'valueishtml'属性设置为true。我需要通过EL将检索到的数据(即没有任何html标记)传递给json变量。有人能告诉我怎么做吗。下面是我需要做的一个例子。请注意这不是一个代码

var mydatawithouthtml = <dsp:valueof param="product.data" valueishtml="true"/>

<json:property name="data" value="${mydatawithouthtml}" />
var mydatawithout html=
目前,“product.data”包含传递给json的html标记。需要没有任何html标记的json数据


TIA

最简单的方法是开发自己的
tagconverter
。实现这一目标的简单方法如下:

package com.acme.tagconverter;

import java.util.Properties;
import java.util.regex.Pattern;

import atg.droplet.TagAttributeDescriptor;
import atg.droplet.TagConversionException;
import atg.droplet.TagConverter;
import atg.droplet.TagConverterManager;
import atg.nucleus.GenericService;
import atg.nucleus.ServiceException;
import atg.servlet.DynamoHttpServletRequest;

public class StripHTMLConverter extends GenericService implements TagConverter {

    private Pattern tagPattern;

    @Override
    public void doStartService() throws ServiceException {
        TagConverterManager.registerTagConverter(this);
    }

    public String convertObjectToString(DynamoHttpServletRequest request, Object obj, Properties attributes) throws TagConversionException {
        return tagPattern.matcher(obj.toString()).replaceAll("");
    }

    public Object convertStringToObject(DynamoHttpServletRequest request, String str, Properties attributes) throws TagConversionException {
        return str;
    }

    public String getName() {
        return "striphtml";
    }

    public TagAttributeDescriptor[] getTagAttributeDescriptors() {
        return new TagAttributeDescriptor[0];
    }

    public void setTagPattern(String tagPattern) {
        this.tagPattern = Pattern.compile(tagPattern);
    }

    public String getTagPattern() {
        return tagPattern.pattern();
    }

}
然后通过包含以下图案的零部件特性文件引用:

$class=com.acme.tagconverter.StripHTMLConverter
tagPattern=<[^>]+>
现在,您应该能够按预期使用它

var mydatawithouthtml = '<dsp:valueof param="product.data" converter="striphtml"/>'
var mydatawithout html=''
var mydatawithouthtml = '<dsp:valueof param="product.data" converter="striphtml"/>'