简体   繁体   English

Handlebars.js未捕获的错误:期望'DATA','ID','INVALID'

[英]Handlebars.js Uncaught Error: Expecting 'DATA', 'ID', got 'INVALID'

Full error: 完整错误:

Uncaught Error: Parse error on line 139:
...rs" ng-class="{ '{{ playerClass(player) 
-----------------------^
Expecting 'DATA', 'ID', got 'INVALID' 

parseError @ handlebars.js:2 parse @ handlebars.js:2 Handlebars.parse @ handlebars.js:2 r @ handlebars.js:3 (anonymous function) @ handlebars.js:3 (anonymous function) @ main.js:212 i @ jquery.js:2 fireWith @ jquery.js:2 ready @ jquery.js:2 J @ jquery.js:2 parseError @ handlebars.js:2 parse @ handlebars.js:2 Handlebars.parse @ handlebars.js:2 r @ handlebars.js:3(匿名函数)@ handlebars.js:3(匿名函数)@ main.js:212我@ jquery.js:2 fireWith @ jquery.js:2 ready @ jquery.js:2 J @ jquery.js:2

HTML: HTML:

<div class="float-left container-60 ">
    <div class="align-center uppercase active-score cricket-table-container container-middle-table">
        <table class="cricket-scoreboard">
            <tr>
                <th></th>
                <th class="color-container-center" ng-repeat="no in numbersToClose track by $index" ng-class="{'bullseye-icon': no === 25 && !isNumberFullyClosed(no), 'bullseye-icon-closed': no === 25 && isNumberFullyClosed(no), 'btn-new-gold':  no !== 25 && isNumberFullyClosed(no), 'btn-new-navy': no !== 25 && !isNumberFullyClosed(no) }">{{ no }}</th>
                <th></th>
            </tr>
            <tr ng-repeat="player in players" ng-class="{ '{{ playerClass(player) }}': player.id === currentPlayer.id }">
                <td class="{{ playerClass(player) }}"></td>
                <td ng-repeat="no in numbersToClose track by $index" ng-class="{ 'btn-new-white': player.id === currentPlayer.id, '{{ playerClass(player) }}': player.id !== currentPlayer.id, 'cricket-hit-zero': [3, null].indexOf(player.numbersToHit[no]) !== -1, 'cricket-hit-one': player.numbersToHit[no] === 2, 'cricket-hit-two': player.numbersToHit[no] === 1, 'cricket-hit-three': player.numbersToHit[no] === 0 }"></td>
            </tr>

        </table>
    </div>
</div>

Main.js: Main.js:

Handlebars.registerHelper('color', function(ndx) {
    if(typeof context === "undefined" || isNaN(ndx)){
        return "";
    }

    return playerColors[ndx];
});

Handlebars.registerHelper('index_of', function(context,ndx,offset) {
    if(typeof offset != "undefined" && !isNaN(offset)) {
        ndx-=offset;
    }

    if(typeof context === "undefined" || isNaN(ndx)){
        return "";
    }
    return context[ndx];
});

Handlebars.registerHelper('container_width', function(length) {
    if(length === 4 || length === 7 || length === 8) {
      return 'container-25'
    }
    if(length === 3 || length === 6 || length === 5) {
      return 'container-33'
    }
    if(length === 2) {
      return 'container-50'
    }
    if(length === 1) {
      return 'container-100'
    }
});

Handlebars.registerHelper('compare', function(lvalue, rvalue, options) {

    if (arguments.length < 3)
        throw new Error("Handlerbars Helper 'compare' needs 2 parameters");

        var operator = options.hash.operator || "==";

        var operators = {
            '==':       function(l,r) { return l == r; },
            '===':      function(l,r) { return l === r; },
           '!==':       function(l,r) { return l !== r; },
            '!=':       function(l,r) { return l != r; },
            '<':        function(l,r) { return l < r; },
            '>':        function(l,r) { return l > r; },
            '<=':       function(l,r) { return l <= r; },
            '>=':       function(l,r) { return l >= r; },
            'typeof':   function(l,r) { return typeof l == r; }
        }

    if (!operators[operator])
        throw new Error("Handlerbars Helper 'compare' doesn't know the operator "+operator);

    var result = operators[operator](lvalue,rvalue);

    if( result ) {
        return options.fn(this);
    } else {
        return options.inverse(this);
    }
});

Handlebars.registerHelper('if_all', function() {
    var args = [].slice.apply(arguments);
    var opts = args.pop();

    var fn = opts.fn;
    for(var i = 0; i < args.length; ++i) {
        if(args[i])
            continue;
        fn = opts.inverse;
        break;
    }
    return fn(this);
});

Handlebars.registerHelper("math", function(lvalue, operator, rvalue, options) {
    lvalue = parseFloat(lvalue);
    rvalue = parseFloat(rvalue);

    return {
        "+": lvalue + rvalue,
        "-": lvalue - rvalue,
        "*": lvalue * rvalue,
        "/": lvalue / rvalue,
        "%": lvalue % rvalue
    }[operator];
});

Handlebars.registerHelper("throw", function(value1, value2, value3, options) {
    if(!value1 && !value2 && !value3) {
        return options.fn(this);
    } else {
        return options.inverse(this);
    }
});

Handlebars.registerHelper("pull", function(value1, value2, value3, options) {
    if(!value1 && value2 && value3) {
        return options.fn(this);
    } else {
        return options.inverse(this);
    }
});

Handlebars.registerHelper("wait", function(value1, value2, value3, options) {
    if(value1 || (value2 && !value3)) {
        return options.fn(this);
    } else {
        return options.inverse(this);
    }
});

var template = Handlebars.compile(source);

I'm not sure whats the real problem. 我不确定真正的问题是什么。

我看不到playerClass助手定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM