Note that there are some explanatory texts on larger screens.

plurals
  1. PODurandal dialog
    primarykey
    data
    text
    <p>Please help. I'm trying to create a knockout template for durandal's dialog plugin. Is there anyone who can give me a basic example for this. Below is my sample code. But I can't make it work..</p> <pre><code>(function (require) { var app = require('durandal/app'), unitofwork = require('services/unitofwork'), dialog = require('plugins/dialog'); var self = this; var uow = unitofwork.create(); var userlist = ko.observableArray(); var selecteduser = ko.observable(); ko.dialog = { // Defines a view model class you can use to populate a grid viewModel: { selecteduser: selecteduser, userlist: userlist, ok: function () { console.log(this.selecteduser()); dialog.close(this, this.selecteduser()); }, cancel: function () { console.log(this.selecteduser()); dialog.close(this, ""); }, canDeactivate: function () { return dialog.showMessage(this.selecteduser()); }, show: function () { var query = breeze.EntityQuery .from("GetUsersByRole") .withParameters({ roleName: "EDITOR" }); // id=3 has two UserRoles uow.userrepository.CustomQuery(query).then(function (data) { userlist(data); }); console.log(userlist); return dialog.show(this); } } }; // Templates used to render the grid var templateEngine = new ko.nativeTemplateEngine(); templateEngine.addTemplate = function (templateName, templateMarkup) { document.write("&lt;script type='text/html' id='" + templateName + "'&gt;" + templateMarkup + "&lt;" + "/script&gt;"); }; templateEngine.addTemplate("ko_dialog_dialog", "\ &lt;div class=\"messageBox\"&gt;\ &lt;div class=\"modal-header\"&gt;\ &lt;h3&gt;\Assign to Editor&lt;/h3&gt;\ &lt;/div&gt;\ &lt;div class=\"modal-body\"&gt;\ &lt;form data-bind=\"submit: ok\"&gt;\ &lt;label&gt;\ Editor Name:&lt;br /&gt;\ &lt;select id=\"selCaseStatus\"\ class=\"span2 shadow_select\"\ data-bind=\"value: selecteduser, options: userlist, optionsText: 'UserName', optionsValue: 'UserName', optionsCaption: '--select--'\"&gt;\ &lt;/select&gt;\ &lt;/label&gt;\ &lt;/form&gt;\ &lt;/div&gt;\ &lt;div class=\"modal-footer\"&gt;\ &lt;button class=\"btn btn-primary\" data-bind=\"click: ok\"&gt;\Ok&amp;nbsp;&lt;i class=\"icon-thumbs-up\"&gt;\&lt;/i&gt;\&lt;/button&gt;\ &lt;button class=\"btn btn-primary\" data-bind=\"click: cancel\"&gt;\Cancel&amp;nbsp;&lt;i class=\"icon-thumbs-down\"&gt;\&lt;/i&gt;\&lt;/button&gt;\ &lt;/div&gt;\ &lt;/div&gt;" ); // The "dialog" binding ko.bindingHandlers.dialog = { init: function () { return { 'controlsDescendantBindings': true }; }, // This method is called to initialize the node, and will also be called again if you change what the grid is bound to update: function (element, viewModelAccessor, allBindingsAccessor) { var viewModel = viewModelAccessor(), allBindings = allBindingsAccessor(); // Empty the element while (element.firstChild) ko.removeNode(element.firstChild); // Allow the default templates to be overridden var panelTemplateName = allBindings.leftPanelTemplate || "ko_dialog_dialog"; //,pageLinksTemplateName = allBindings.simpleGridPagerTemplate || "ko_simpleGrid_pageLinks"; // Render the main grid var panelContainer = element.appendChild(document.createElement("DIV")); ko.renderTemplate(panelTemplateName, viewModel, { templateEngine: templateEngine }, panelContainer, "replaceNode"); } }; })(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload