添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
朝气蓬勃的紫菜  ·  SPI_InitStructure.SPI_ ...·  1 月前    · 
痴情的饼干  ·  pandas ...·  1 年前    · 
爽快的佛珠  ·  springboot maven ...·  1 年前    · 
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.