简体   繁体   English

Ko.bindinghandlers无法在Chrome中工作

[英]Ko.bindinghandlers not working in Chrome

I've created a bindingHandler: 我创建了一个bindingHandler:

ko.bindingHandlers.highlight = {
        update: function (element, valueAccessor) {
            $(element).fadeTo("fast", 0.03);
            $(element).fadeTo("fast", 1);
            $(element).fadeTo("fast", 0.03);
            $(element).fadeTo("fast", 1);
            $(element).fadeTo("fast", 0.03);
            $(element).fadeTo("fast", 1);
            $(element).fadeTo("fast", 0.03);
            $(element).fadeTo("fast", 1);
        }
};

...and bound it to an observableArray: ...并将其绑定到observableArray:

<div data-bind="foreach: contactsInfrastructure">
                <div class="contact" data-bind="highlight: Contact">
                    <div class="contactAvailability">
                        <div class="contactAvailabilityColor" data-bind="css: "availabilityCssClass"></div>
                    </div>
                    <div class="contactName" ><span data-bind="text: name"</span></div>
                    <!-- <div class="contactNote ellipseText" data-bind="text: group"></div> -->
                </div>
            </div>

It works fine in Firefox, but in Chrome this error is returned: Uncaught ReferenceError: 它在Firefox中工作正常,但在Chrome中会返回此错误:未捕获的ReferenceError:

Unable to parse bindings.
Bindings value: highlight: Contact
Message: Contact is not defined

At first I thought it was caused by the DOM not being ready, but that is not the case. 起初我以为它是由DOM没有准备好引起的,但事实并非如此。

When you use contact without any quotes, Knockout searches for an observable with the name Contact . 当您使用没有任何引号的联系人时,Knockout会搜索名为Contact的observable。 However, there is no such Observable in your ViewModel. 但是,ViewModel中没有这样的Observable。

It seems you also did not use this word in your custom handler. 您似乎也没有在自定义处理程序中使用此单词。 If you need to pass this word into your handler as text, you can wrap it inside quotes => 'Contact' 如果你需要将这个单词作为文本传递给你的处理程序,你可以将它包装在quotes =>'Contact'中

<div class="contact" data-bind="highlight: 'Contact'"> 
OR
<div class="contact" data-bind="highlight: true">

Is Contact supposed to be an element of the contactsInfrastructure array? Contact应该是contactsInfrastructure数组的一个元素吗? Because, if so, you should be using <div class="contact" data-bind="highlight: $data"> instead. 因为,如果是这样,你应该使用<div class="contact" data-bind="highlight: $data">代替。

在html中绑定时,实体名称必须是关于列名/ entityName的camelcase。

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

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