KnockoutJS`with`绑定和IE8

时间:2013-04-02 17:59:18

标签: javascript html internet-explorer-8 knockout.js

出于某种原因,我的代码在IE8中生成了以下错误,但在任何普通浏览器中都没有。

SCRIPT5022: Unable to parse bindings.
Message: TypeError: 'logoSrc' is undefined;
Bindings value: 'attr': { 'src': logoSrc } 

我确认logoSrc属性确实已定义,即使在IE8中,在绑定之前,但仍然失败。禁用与logoSrc的绑定只会导致下一个绑定失败。

html如下。我知道我之前使用过带绑定,所以我很确定这不是问题,而且html似乎已经正确关闭了。

<div data-bind="visible: mode() === 'print'" class="container-fluid">
    <!-- ko with: printVm -->
    <div class="row-fluid">
        <div class="span12">
            <div class="page-header">
                <div class="pull-right" style="width:140px;height:60px;overflow:hidden;">
                    <img data-bind="'attr': { 'src': logoSrc }" src="" />
                </div>
                <h2>Invoice Statement - <span data-bind="text: itemZeroClientName"></span></h2>
            </div>
            <strong>Invoice number:</strong> <span data-bind="text: invoiceId"></span>
            <strong>Invoice date:</strong> <span data-bind="text: userInfo().invoiceDateDisplay"></span>
            <strong>Client number:</strong> <span data-bind="text: itemZeroClientId">22365</span>
            <hr />
        </div>
    </div>
    <div class="row-fluid">
        <div class="span6 cr-tablet6 cr-phone6">
            <h4>Billed by <span data-bind="text: companyNameDisplay"></span></h4>
            <span data-bind="html: companyInfo"></span>
        </div>
        <div class="span6 cr-tablet6 cr-phone6">
            <h4>Billed to</h4>
            <span data-bind="html: clientInfoDisplay"></span>
        </div>
    </div>

    <div class="row-fluid">
        <div class="span12">
            <hr />
            <table id="printInvoiceTable" class="table">
                <thead>
                <tr>
                    <th class="date">Date</th>
                    <th class="name">Provider</th>
                    <th class="code">Proc Code</th>
                    <th class="location">Location</th>
                    <th class="time">Hours</th>
                    <th class="units">Units</th>
                    <th class="charge">Charges</th>
                </tr>
                </thead>
                <tbody data-bind="foreach: items">
                    <tr>
                        <td data-bind="text: dateDisplay"></td>
                        <td data-bind="text: orgName"></td>
                        <td data-bind="text: procedureCodeString"></td>
                        <td data-bind="text: location"></td>
                        <td class="formatted-number" data-bind="text: timeWorkedHrs"></td>
                        <td class="formatted-number" data-bind="text: (unitsOfService() || 0).toFixed(2)"></td>
                        <td class="formatted-currency" data-bind="text: (clientCharges() || 0).toFixed(2)"></td>
                    </tr>
                </tbody>
                <tfoot>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td class="formatted-number" data-bind="text: totalWorkedHours"></td>
                        <td class="formatted-number" data-bind="text: totalUnitsOfService"></td>
                        <td class="formatted-currency" data-bind="text: totalClientRate"></td>
                    </tr>
                </tfoot>
            </table>
        </div>
    </div>
    <!-- /ko -->
</div>

2 个答案:

答案 0 :(得分:2)

如上所述,问题似乎是IE8删除了注释(因此在某些条件下删除了虚拟绑定)并且已经reported on the knockout forums

答案 1 :(得分:0)

我在IE8中使用with和jquery文件时遇到了问题。我也有评论问题,并能够通过逃避评论条件来解决它。淘汰赛网页提到了这个警告。