Javascript Equivalent to C# LINQ Select

Yes, Array.map() or $.map() does the same thing. //array.map: var ids = this.fruits.map(function(v){ return v.Id; }); //jQuery.map: var ids2 = $.map(this.fruits, function (v){ return v.Id; }); console.log(ids, ids2); http://jsfiddle.net/NsCXJ/1/ Since array.map isn’t supported in older browsers, I suggest that you stick with the jQuery method. If you prefer the other one for some reason you … Read more

How can I get Knockout JS to data-bind on keypress instead of lost-focus?

<body> <p>First name: <input data-bind=”value: firstName, valueUpdate: ‘afterkeydown'” /></p> <p>Last name: <input data-bind=”value: lastName, valueUpdate: ‘afterkeydown'” /></p> <h2>Hello, <span data-bind=”text: fullName”> </span>!</h2> </body> From the documentation Additional parameters valueUpdate If your binding also includes a parameter called valueUpdate, this defines which browser event KO should use to detect changes. The following string values are the … Read more

Difference between knockout View Models declared as object literals vs functions

There are a couple of advantages to using a function to define your view model. The main advantage is that you have immediate access to a value of this that equals the instance being created. This means that you can do: var ViewModel = function(first, last) { this.first = ko.observable(first); this.last = ko.observable(last); this.full = … Read more

KnockOutJS – Multiple ViewModels in a single View

Knockout now supports multiple model binding. The ko.applyBindings() method takes an optional parameter – the element and its descendants to which the binding will be activated. For example: ko.applyBindings(myViewModel, document.getElementById(‘someElementId’)) This restricts the activation to the element with ID someElementId and its descendants. See documentation for more details.

How to debug template binding errors for KnockoutJS?

One thing that I do quite often when there is an issue with what data is available at a certain scope is to replace the template/section with something like: <div data-bind=”text: ko.toJSON($data)”></div> Or, if you want a slightly more readable version: <pre data-bind=”text: JSON.stringify(ko.toJS($data), null, 2)”></pre> This will spit out the data that is being … Read more

Getting “The JSON request was too large to be deserialized”

You have to adjust the maxJsonLength property to a higher value in web.config to resolve the issue. <system.web.extensions> <scripting> <webServices> <jsonSerialization maxJsonLength=”2147483644″/> </webServices> </scripting> </system.web.extensions> Set a higher value for aspnet:MaxJsonDeserializerMembers in the appSettings: <appSettings> <add key=”aspnet:MaxJsonDeserializerMembers” value=”150000″ /> </appSettings> If those options are not working you could try creating a custom json value provider … Read more

What are the key differences between Meteor, Ember.js and Backbone.js? [closed]

There is a nice run down/comparison of various MVx JS frameworks here http://codebrief.com/2012/01/the-top-10-javascript-mvc-frameworks-reviewed/ it’s followed by a good discussion in the comments too. I think I’ve seen Gordon (who wrote it) on here so maybe you’ll get a reply from him. I’d say if you are looking to learn this style of application development then … Read more

Can you call ko.applyBindings to bind a partial view?

ko.applyBindings accepts a second parameter that is a DOM element to use as the root. This would let you do something like: <div id=”one”> <input data-bind=”value: name” /> </div> <div id=”two”> <input data-bind=”value: name” /> </div> <script type=”text/javascript”> var viewModelA = { name: ko.observable(“Bob”) }; var viewModelB = { name: ko.observable(“Ted”) }; ko.applyBindings(viewModelA, document.getElementById(“one”)); ko.applyBindings(viewModelB, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)