How to work $linq with knockout js

Feb 24, 2013 at 12:22 PM
i need to work your library with knockout js. there is any compatibility pack?
Coordinator
Feb 26, 2013 at 3:31 AM
There are two ways to use $linq with knockout's observableArray. The first, uses a snapshot of of the observableArray's value, as demonstrated by the following code:
var arr = ko.observableArray([{ word: 'one', number: 1 }, { word: 'two', number: 2 }]);
var linqObj = $linq(arr());

// arr2 = [ 1, 2 ]
var arr2 = linqObj.select('x => x.number').toArray();

arr().push({ word: 'three', number: 3 });

// arr2 = [ 1, 2 ] (still)
arr2 = linqObj.select('x => x.number').toArray();
Notice that the results of the second $linq select() call, here, are not changed by the call to the observableArray's push() call.

The second way to use $linq with knockout's observableArray involves causing the $linq object to directly use the array that the observableArray is managing, as demonstrated by the following code:
var arr = ko.observableArray([{ word: 'one', number: 1 }, { word: 'two', number: 2 }]);
var linqObj = new linq(arr(), false);

// arr2 = [ 1, 2 ]
var arr2 = linqObj.select('x => x.number').toArray();

arr().push({ word: 'three', number: 3 });

// arr2 = [ 1, 2, 3 ]
arr2 = linqObj.select('x => x.number').toArray();
The two examples differ in how they construct a $linq object. The second example uses the linq constructor and passes 'false' as the second parameter, causing the linq object to not make an internal copy of the array passed as the first parameter (as it does by default and with the first example).
Jul 31, 2013 at 12:21 PM
Thank you very much for your reply..

it works....