return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - How To Read Values Within Arrays In Immutable.js - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How To Read Values Within Arrays In Immutable.js - Stack Overflow

programmeradmin1浏览0评论

Im a bit confused about this and cant seem to work this out.

Say I have this:

const AnObj = Immutable.Map({
 a : "a",
 b : Immutable.List.of(
  a,
  b,
  c,
  Immutable.Map({
   a : "a"
  })
 )
});

With Immutable Maps, we use strings within get() to find the corresponding properties. How do we read array values?

Im a bit confused about this and cant seem to work this out.

Say I have this:

const AnObj = Immutable.Map({
 a : "a",
 b : Immutable.List.of(
  a,
  b,
  c,
  Immutable.Map({
   a : "a"
  })
 )
});

With Immutable Maps, we use strings within get() to find the corresponding properties. How do we read array values?

Share Improve this question asked May 5, 2016 at 13:06 KayoteKayote 15.7k26 gold badges96 silver badges152 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7 +50

Disclaimer - This applies to all Immutable types, not just List.

Several ways -

  1. The get method - AnObj.get('b').get(3).get('a') (Thanks @stas). This is useful when the structure is not very deep. As you see, the syntax is very verbose.

  2. The succinct getIn - AnObj.getIn(['b', 3, 'a']) I love this because this pattern allows having a generic getter and I can toss the key-path around to the various ponents.

  3. The veritable valueSeq/entrySeq, when you want all the values and don't care for indices - AnObj.get('b').valueSeq() This is useful when the list is huge and you want to delay the iteration until its absolutely needed. This is the most performant of them all.

You can pass numeric zero-based indexes to List.get():

AnObj.get('b').get(3).get('a')

See https://facebook.github.io/immutable-js/docs/#/List/get.

发布评论

评论列表(0)

  1. 暂无评论