knockout.js - Is it possible to toggle a components template with the params object in the binding -
I have not read from the documents that it is possible to determine which template the parameter was seen in the model It is also not convinced that this is a good idea, just wanted to know if it was possible.
One of my current solutions is a bella:
This issue basically has to be a master component that determines all other components if it is read only. It can be done in JS in a config phase but I just want to know that there is no clear or best practice about this.
Because jsbins are apparently complex.
JS:
var readOnlyLoader = {getConfig: function (name, callback) {callback ({template: {element: name + "-readonly"}}); }}; Ko.components.register ("all-component", {viewModel: function (p) {console.log (p.readonly); if (p.readonly) {ko.components.loaders.unshift (readOnlyLoader);} Return page .data;}, template: {element: "all-template"}}); Ko.components.register ("text-editor-component", {viewModel: function (params) {this.content = params.content; console.log (this.readonly); // If only read, then a Use a different template}, Template: {element: "text-editor-template"}}); Ko.applyBindings ({text: ko.observable ("test")});
HTML:
& lt; Input type = 'text' data-bind = 'value: text' / & gt; & Lt; All-Component Parameters = "Data: $ Data, Readable: True" & gt; & Lt; / All-Component & gt; & Lt; Template id = 'All-template' & gt; & Lt; Text-editor-component params = 'content: text' & gt; & Lt; / Text-editor-component> & Lt; / Template & gt; & Lt; Template id = 'Text-Editor-Template' & gt; & Lt; Input type = 'text'data-bind =' value: content '/ & gt; & Lt; / Template & gt; & Lt; Template id = 'Text-editor-component-readonly' & gt; & Lt; Span data-bind = 'text: content' & gt; & Lt; / Span & gt; & Lt; / Template & gt;
Comments
Post a Comment