添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
阳刚的橙子  ·  事件 - JavaScript教程 - ...·  4 月前    · 
讲道义的馒头  ·  JavaScript - 實現 input ...·  3 月前    · 
面冷心慈的花卷  ·  Interacting with code ...·  2 月前    · 
豪情万千的键盘  ·  Loading an html form ...·  1 月前    · 
大气的作业本  ·  collect(Collectors.toM ...·  1 年前    · 
英俊的汤圆  ·  typescript the return ...·  2 年前    · 
愤怒的苹果  ·  golang aws-sdk-go 之 ...·  3 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm new to javascript and i just wanted to know if there is a LinQ equivalent in vue. My goal is to do something like this :

this.selection = this.clientsComplete.Where(
        c => c.id == eventArgs.sender.id);

On a collection made like this :

clientsComplete: [
          id: 1,
          title: "Client1",
          description: "Unknown",
          sites: [
            { id: 1, title: "Site1-1", description: "Unknown" },
            { id: 2, title: "Site1-2", description: "Unknown" }
          id: 2,
          title: "Client2",
          description: "Inconnue",
          sites: [
            { id: 1, title: "Site2-1", description: "Unknown" },

Is this event possible in vue? I can't find anything in the documentation about selection in Lists.

If there is no LinQ equivalent, do I have to do a foreach to find my object ?

How about using plain javascript? There are powerful array functions that can get you there.

For example:

this.clientsComplete.filter(c => c.id == eventArgs.sender.id) is very similar to what LINQ Where does.

More info here.

Edit: this uses ES6 arrow functions but it can also be written without it.

Exactly, wanted to write the same thing, you beat me to it @paqash ;-). But indeed the built in methods can make you go a long way. – Yves Schelpe Sep 25, 2018 at 9:36

https://www.npmjs.com/package/manipula is javascript LINQ equivalent. Example:

this.selection = Manipula.from(this.clientsComplete)
                         .where(c=> c.id == eventArgs.sender.id)
                         .toArray();
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.