MVC Knockout JS inside JQuery dialog

前端 未结 1 989
抹茶落季
抹茶落季 2020-12-16 06:16

I am using knockout js on a view to display a list of fields (ie, first name, last name, etc). The fields are listed inside a knockout template using the an observable array

相关标签:
1条回答
  • 2020-12-16 07:13

    Here is a sample that might be similar to what you are doing: http://jsfiddle.net/rniemeyer/WpnTU/

    It sets up the dialog when the page loads, but doesn't open it. Then, there is a custom binding handler that will get called whenever a "selectedItem" observable is populated (which could be with an existing item or a new item).

    The simple custom binding handler looks like:

    //custom binding handler that opens the jQuery dialog, if the selectedProduct is populated
    ko.bindingHandlers.openDialog = {
        update: function(element, valueAccessor) {
            var value = ko.utils.unwrapObservable(valueAccessor());
            if (value) {
                $(element).dialog("open");
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题