3

Is it possible to do in jquery something similar to this C# example:

LoopModel = Model.Fields
                    .Where(p => p.Key < 1000 && !Model.FieldHandled.ContainsKey(p.Key) && !FieldsValid.ContainsKey(p.Key))
                    .OrderBy(p => p.Value.SortOrder).ThenBy(p => p.Value.FieldTypeID).ThenBy(p => p.Value.FieldLabel);

I can do

var fields = @Html.Raw(JsonConvert.SerializeObject(Model.Fields));

So I want to be able to select certain fields from "fields".

Thanks

3 Answers3

2

Use filter. No libraries required.

Here is an example from the link:

const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const result = words.filter(word => word.length > 6);

console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]
James Brierley
  • 4,630
  • 1
  • 20
  • 39
1

I prefer Lodash or Underscore. They are widely used in various JS libs and right now I think they are the most JavaScript-ish solution. They also guarantee support for legacy browsers, having lots of performance enhancements. I think it's worth to learn them.

https://lodash.com/ http://underscorejs.org/

See the comparison here: Differences between lodash and underscore

Community
  • 1
  • 1
Gábor Imre
  • 5,899
  • 2
  • 35
  • 48
0

You can use JLinq.js library. It provides same functions as C#

Akshay
  • 530
  • 7
  • 20