Javascript 如何解决淘汰赛中的参考错误;加上:“;上下文

Javascript 如何解决淘汰赛中的参考错误;加上:“;上下文,javascript,jquery,knockout.js,Javascript,Jquery,Knockout.js,下面这行有什么问题 <div id="dialog" data-bind="with: SelectedText, dialog: {'autoOpen': false, 'title': textbatchTitle }, dialogVisible: $root.isMetadataDialogOpen "></div> 埃里克·布伦登基本上给了你答案: <div id="dialog" data-bind="with: SelectedText, dial

下面这行有什么问题

 <div id="dialog" data-bind="with: SelectedText, dialog: {'autoOpen': false, 'title': textbatchTitle }, dialogVisible: $root.isMetadataDialogOpen "></div>

埃里克·布伦登基本上给了你答案:

<div id="dialog" data-bind="with: SelectedText, dialog: {'autoOpen': false, 'title': textbatchTitle }, dialogVisible: $root.isMetadataDialogOpen ">
    <!-- INSIDE here, 'SelectedText' is the binding context, and 'textbatchTitle' works. However, the div with id = "dialog" ITSELF does not yet have the binding context 'SelectedText', instead its context is the parent of 'SelectedText'
</div>


您的对象“SelectedText”对象包含哪些属性?如果它没有属性textbatchTitle,那么这就是问题所在。显然,当send div工作并显示textbatchTitle时,它必须有属性,no?,来自敲除文档:“with binding创建一个新的绑定上下文,以便将子元素绑定到指定对象的上下文中。”在这种情况下,您使用的是子体元素。
ko.bindingHandlers.dialog = {
    init: function (element, valueAccessor, allBindingsAccessor) {
        var options = ko.utils.unwrapObservable(valueAccessor()) || {};

        //do in a setTimeout, so the applyBindings doesn't bind twice from element being copied and moved to bottom
        setTimeout(function () {
            options.close = function () {
                allBindingsAccessor().dialogVisible(false);
            };

            $(element).dialog(ko.toJS(options));
        }, 0);

        //handle disposal (not strictly necessary in this scenario)
        ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
            $(element).dialog("destroy");
        });
    },
    update: function (element, valueAccessor, allBindingsAccessor) {
        var shouldBeOpen = ko.utils.unwrapObservable(allBindingsAccessor().dialogVisible),
            $el = $(element),
            dialog = $el.data("uiDialog") || $el.data("dialog"),
            options = valueAccessor();

        //don't call dialog methods before initilization
        if (dialog) {
            $el.dialog(shouldBeOpen ? "open" : "close");

            for (var key in options) {
                if (ko.isObservable(options[key])) {
                    $el.dialog("option", key, options[key]());
                }
            }
        }
    }
};
<div id="dialog" data-bind="with: SelectedText, dialog: {'autoOpen': false, 'title': textbatchTitle }, dialogVisible: $root.isMetadataDialogOpen ">
    <!-- INSIDE here, 'SelectedText' is the binding context, and 'textbatchTitle' works. However, the div with id = "dialog" ITSELF does not yet have the binding context 'SelectedText', instead its context is the parent of 'SelectedText'
</div>
<div id="Div1" class="textbatchdetails" data-bind="with: SelectedText" >
     <!-- In here, just like above, the binding context is 'SelectedText'. So on this level, 'textbatchTitle' is fine
     <div>  
         <input type="text" name="textbatchTitle" data-bind="value: textbatchTitle, valueUpdate: 'afterkeydown'"  />
     </div>
</div>
<div data-bind="with: SelectedText">
    <div id="dialog" data-bind="dialog: {'autoOpen': false, 'title': textbatchTitle }, dialogVisible: $root.isMetadataDialogOpen "></div>
</div>
    <div id="dialog" data-bind="with: SelectedText, dialog: {'autoOpen': false, 'title': SelectedText.textbatchTitle }, dialogVisible: $root.isMetadataDialogOpen ">
    <div id="dialog" data-bind="with: SelectedText, dialog: {'autoOpen': false, 'title': SelectedText() ? SelectedText().textbatchTitle : '' }, dialogVisible: $root.isMetadataDialogOpen ">