My team need to developp a mobile website with an administration part.
I would like to work a layer based on webAPi with knockout.js in the design layer. Nevertheless after to use it a little time, I encountered several
issues,
first you need to recreate the same mode in javascript side.
second one, I try to access to data from object build like that : object A -> property List<Object B> -> property Title and property Description, I need to use a compute method to permit to display on the same line Title and Description, but i dont find
an easy way so for the moment it's like below. It's complicate, if I need to search a long time to find how to add a compute on the list News, it's not the right technical solution.
We are using Knockout successfully with WCF and JsonResult. It is also easy to use knockout with Web API as it is p to you how you retrieve data and serve it to Knockout. Knockout is not about reading and saving data - it is about implementing MVVM pattern
on user-interface side.
If my blog post leaves questions up then please feel free to ask more :)
Don't forget to mark solution providing post as "Answered".
I agree with you about what is supposed to do Knockout. I am not convince it should be used because you need to duplicate the object from the server on the client side and the time to learn is more long.
Other issue:
Exemple I have a class user with a property List<News>
I found many samples about how to use the ko.computed on the self object but when you decide to customize the behavior for an element as List<News> for each elements returned, it's not simple. I don't find an easy to show two properties from news.
I notice when an issue, I don't find a clear issue throwed by Knockout.js
BUT regarding your answer, I supposed I don't pass enough time to work on it, so for the current project we try to use it.
If it doesn't work, we go back to old version Controler + simple javascript.
Knockout has some overhead to coding, of course. You have to create view models and if needed you have to modify objects you get from web server (like making some properties observable or add new properties). I think other frameworks like this have same
overhead.
Knockout takes some time to get used with it. As a server-side guy for me it was damn kinky at first place. But I went with it, I ran into troubles, I solved the problems and after some weeks I was able to write working code on it with no markable issues.
So be prepared for some difficulties. Later it saves you hell load of time you otherwise spend on inventing the same wheel but painful way.
I even managed to get jQuery UI widgets to work with Knockout. Accordion and tabs, by example. I got over huge load of nasty looking HTML and long JavaScript once I moved code to Knockout. So you will benefit later for sure.
Don't forget to mark solution providing post as "Answered".
I convince I need to improve my knowledge about Knockout. So ok let's rock, I based my new project on WebAPI and Knockout for the backend at first. If everything goes fine, I will continu to use for the frontend otherwise I go back to controller + javascript.
Thank you really for your experience, so it possible to use Jquery UI and Lockout very easy after to have enough XP, a good sound.
myddoc
Member
49 Points
42 Posts
Point of View Use or not knockout.js with webApi
Jan 26, 2013 07:03 AM|LINK
Hi,
My team need to developp a mobile website with an administration part.
I would like to work a layer based on webAPi with knockout.js in the design layer. Nevertheless after to use it a little time, I encountered several
issues,
first you need to recreate the same mode in javascript side.
second one, I try to access to data from object build like that : object A -> property List<Object B> -> property Title and property Description, I need to use a compute method to permit to display on the same line Title and Description, but i dont find an easy way so for the moment it's like below. It's complicate, if I need to search a long time to find how to add a compute on the list News, it's not the right technical solution.
<ul id="update-News" data-bind="foreach: $data.News"> <p data-bind="text : $data.Title"></p> <p data-bind="text : $data.Description"></p> </ul>So my conclusion is lockout.js is not the right solution,
For the backoffice: 70% from the duration/tasks
I think to write controllers inherit from ApiController.
Between The design and ApiController I build some classes inherit from Controller.
I use the generation View and controller from ASP.NET MVC4 without to use knockout.js.
For the frontend: 30% from the duration/tasks
Try to implement lockout.js and call directly webapi build in the backend.
What is your opinion or point of view regarding your recently projects?
Best regards,
Alexandre
myddoc
Member
49 Points
42 Posts
Re: Point of View Use or not knockout.js with webApi
Jan 26, 2013 09:05 PM|LINK
Hi,
Is someone can share his experience by using knockout js?
best regards,
Alexandre
DigiMortal
Contributor
5728 Points
954 Posts
MVP
Re: Point of View Use or not knockout.js with webApi
Jan 28, 2013 12:50 PM|LINK
Blogged it about yesterday: My experiences with Knockout
We are using Knockout successfully with WCF and JsonResult. It is also easy to use knockout with Web API as it is p to you how you retrieve data and serve it to Knockout. Knockout is not about reading and saving data - it is about implementing MVVM pattern on user-interface side.
If my blog post leaves questions up then please feel free to ask more :)
Also visit my ASP.NET blog or follow me @ Twitter:twitter.com/gpeipman
myddoc
Member
49 Points
42 Posts
Re: Point of View Use or not knockout.js with webApi
Jan 28, 2013 06:13 PM|LINK
Hi,
Thank for your answer.
I agree with you about what is supposed to do Knockout. I am not convince it should be used because you need to duplicate the object from the server on the client side and the time to learn is more long.
Other issue:
Exemple I have a class user with a property List<News>
I found many samples about how to use the ko.computed on the self object but when you decide to customize the behavior for an element as List<News> for each elements returned, it's not simple. I don't find an easy to show two properties from news.
I notice when an issue, I don't find a clear issue throwed by Knockout.js
BUT regarding your answer, I supposed I don't pass enough time to work on it, so for the current project we try to use it.
If it doesn't work, we go back to old version Controler + simple javascript.
best regards,
Alexandre
DigiMortal
Contributor
5728 Points
954 Posts
MVP
Re: Point of View Use or not knockout.js with webApi
Jan 28, 2013 06:19 PM|LINK
Knockout has some overhead to coding, of course. You have to create view models and if needed you have to modify objects you get from web server (like making some properties observable or add new properties). I think other frameworks like this have same overhead.
Knockout takes some time to get used with it. As a server-side guy for me it was damn kinky at first place. But I went with it, I ran into troubles, I solved the problems and after some weeks I was able to write working code on it with no markable issues. So be prepared for some difficulties. Later it saves you hell load of time you otherwise spend on inventing the same wheel but painful way.
I even managed to get jQuery UI widgets to work with Knockout. Accordion and tabs, by example. I got over huge load of nasty looking HTML and long JavaScript once I moved code to Knockout. So you will benefit later for sure.
Also visit my ASP.NET blog or follow me @ Twitter:twitter.com/gpeipman
myddoc
Member
49 Points
42 Posts
Re: Point of View Use or not knockout.js with webApi
Jan 30, 2013 05:27 PM|LINK
Hi,
I convince I need to improve my knowledge about Knockout. So ok let's rock, I based my new project on WebAPI and Knockout for the backend at first. If everything goes fine, I will continu to use for the frontend otherwise I go back to controller + javascript.
Thank you really for your experience, so it possible to use Jquery UI and Lockout very easy after to have enough XP, a good sound.
best regards,
Alexandre