javascript - Generating Knockout Markup in MVC 3 -


We are currently writing a new infrastructure for our MVC client and we are trying to create it so that Developers should not be right enough JavaScript (the current development pool is primarily desktop based)

Whatever I've done for our knockout script, it has created an extension method that uses the reflection model All knockout pieces on the basis of Does not generate .. Get it

For example, say we have had this class

  public class AppViewModel {public string Prthamnam {; Set;} public string LastName {get; Set;}}  

will be created and added in the following view

  function AppViewModel () {this.firstName = ko.observable ('Bob') ; This.lastName = ko.observable ('Smith'); }  

The ID is actually like, support from the model is computed values. But I can not understand a way to do it

such as

  Public full name () {return.FirstName + "" + this.LastName} " 

Something will be generated

  This full name = Ko.computed (function () {this return.firstName () + "" + this.lastName ();}, this);  

So to clarify it - what I'm trying to do produces values ​​calculated based on my model.

Thanks for any help

Happy. PAL

What next steps are described above, your scenario is a 'T':

< P>

There is a transcription from the page here:

Model:

  Public class helowword model {public string first Name {get; Set; } Public String LastName {get; Set; } Public expression & lt; Funk & lt; String & gt; & Gt; Full name () {return () = & gt; First name + "" + last name; }}  

Razor:

  @ PerpetuumSoft.Knockout @ model KnockoutMvcDemo.Models.HelloWorldModel @ {var to = HTML CreateKnockoutContext (); } & Lt; P & gt; First name: @ ko.Html.TextBox (M => M. Fisanam) & lt; / P & gt; & Lt; P & gt; Last name: @ ko.Html.TextBox (m = & gt; m.LastName) & lt; / P & gt; & Lt; H2 & gt; Hello, @ ko.Html.Span (m => m.FullName ())! & Lt; / H2 & gt; @ Ko.Apply (Model)  

Controller:

  Public class HelloWorldController: BaseController {Public ActionResult Index () {InitializeViewBag ("Hello world"); See refresh (new hallowd model {first name = "steve", last name = "sanderson"}); }}  

Autogenerated HTML:

  & lt; P & gt; First name: & lt; Input Data-Bind = "Value: First Name" /> & lt; / P & gt; & Lt; P & gt; Last name: & lt; Input data-bind = "value: last name" /> & Lt; / P & gt; & Lt; H2 & gt; Hello, & lt; Span data-bound = "text: full name" & gt; & Lt; / Span & gt; & Lt; / H2 & gt; & Lt; Script type = "text / javascript" & gt; Var viewModelJs = {"First name": "Steve", "Lastname": "Sanderson"}; Var VisualModel = Ko.Mapping.frames (seeModelJS); Please seeModel.flannname = COPPID (function (try) Return it. First name () + '' This .listname ();} Catch (e) {return tap;};}, View modal); Ko.applyBindings (ViewModel); & Lt; / Script & gt;  

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -