如何通过字符串模板生成$(美元)符号

时间:2015-11-20 10:40:27

标签: html stringtemplate-4

我的目标是使用字符串模板为html文件生成代码。 html文件包含一些我们需要美元符号的ajax代码。我无法使用字符串模板文件打印$ dollar符号,因为$ dollar符号表示字符串模板中的EOF。

client.html文件的

代码如下所示:

<script>
$(document).ready(function () {
//Device developer will specify maxDataPoints display in a chart at a time
    var maxDataPoints = 10;
    //Device developer will specify type of charts 
    var chart = new google.visualization.LineChart($('#chart')[0]); 
    var data = google.visualization.arrayToDataTable([ 
    // Device developer will specify what kind of data to be display in chart .....(A)
        ['Time', 'Temperature'],
        [getTime(), 0]
    ]); 
    var options = { 
    //Device developer will specify title,axis label  for chart
        title: 'Temperature',
        hAxis: {title: 'Time', titleTextStyle: {color: '#333'}}, //Added hAxis and vAxis label
        vAxis: {title: 'TempValue',  minValue: 0, titleTextStyle: {color: '#333'}},
        curveType: 'function',
        animation: {
            duration: 1000,
            easing: 'in'
        },
        legend: {position: 'bottom'}
    };
    function addDataPoint(dataPoint) { 
        if (data.getNumberOfRows() > maxDataPoints) {
            data.removeRow(0);
        }
        // Device developer will specify following value based on ref A
        data.addRow([getTime(), dataPoint.value]);
        chart.draw(data, options); 
    }
    function getTime() {
        var d = new Date();
        return d.toLocaleTimeString();
    }
    function doPoll() { 

        $.getJSON('http://localhost:8686/temperatureData',
                    function (result) {
                    addDataPoint(result); 
                    // Device developer will specify polling time 
                    setTimeout(doPoll,1000);
                });

    }
    doPoll();
});

字符串模板出错如下所示:

problem parsing template 'JavaSE/client'
line 21:10: expecting '$', found '<EOF>'
at     org.antlr.stringtemplate.language.DefaultTemplateLexer.nextToken(DefaultTemplateLexer.java:149)
at antlr.TokenBuffer.fill(TokenBuffer.java:69)
at antlr.TokenBuffer.LA(TokenBuffer.java:80)
at antlr.LLkParser.LA(LLkParser.java:52)
at org.antlr.stringtemplate.language.TemplateParser.template(TemplateParser.java:116)
at org.antlr.stringtemplate.StringTemplate.breakTemplateIntoChunks(StringTemplate.java:850)
at org.antlr.stringtemplate.StringTemplate.setTemplate(StringTemplate.java:441)
at org.antlr.stringtemplate.StringTemplateGroup.defineTemplate(StringTemplateGroup.java:679)
at org.antlr.stringtemplate.StringTemplateGroup.loadTemplate(StringTemplateGroup.java:553)
at org.antlr.stringtemplate.StringTemplateGroup.loadTemplate(StringTemplateGroup.java:629)
at org.antlr.stringtemplate.StringTemplateGroup.loadTemplateFromBeneathRootDirOrCLASSPATH(StringTemplateGroup.java:597)
at org.antlr.stringtemplate.StringTemplateGroup.lookupTemplate(StringTemplateGroup.java:480)
at org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:392)
at org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:404)
at iotsuite.codegenerator.JavaFrameworkFromST.generateVisualization_Client(JavaFrameworkFromST.java:180)
at iotsuite.compiler.ActuatorCompiler.generateVisualization_Client(ActuatorCompiler.java:108)
at iotsuite.compiler.ActuatorCompiler.generateActuatorCode(ActuatorCompiler.java:67)
at iotsuite.parser.VocabSpecParser.actuator_def(VocabSpecParser.java:1043)
at iotsuite.parser.VocabSpecParser.abilities_def(VocabSpecParser.java:318)
at iotsuite.parser.VocabSpecParser.vocabSpec(VocabSpecParser.java:132)
at iotsuite.parser.Main.main(Main.java:30)

1 个答案:

答案 0 :(得分:0)

你有没有试过像

这样的东西
var dollarsign = '$'
alert(dollarsign);

通过这种方式,您可以打印'$',而不会将脚本视为'$'

https://jsfiddle.net/Lcm3hp3f/