- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是album.tracks.items
的json内容
[{
"disc_number": 1,
"duration_ms": 220613,
"explicit": false,
"external_urls": {
"spotify": "https://open.spotify.com/track/5dcQ8zP4ruXLGvxvnaqiIR"
},
"href": "https://api.spotify.com/v1/tracks/5dcQ8zP4ruXLGvxvnaqiIR",
"id": "5dcQ8zP4ruXLGvxvnaqiIR",
"is_local": false,
"name": "It Ain't Love (feat. Lil Mo)",
"preview_url": "https://p.scdn.co/mp3-preview/b0b7c4631088cf6c358f3fd2f368621064c81169?cid=774b29d4f13844c495f206cafdad9c86",
"track_number": 1,
"type": "track",
"uri": "spotify:track:5dcQ8zP4ruXLGvxvnaqiIR",
"url_path": "http://localhost:5000/music/4tnnrgXBrdF0b4q3lZqL0v/1/1"
},
{
"disc_number": 1,
"duration_ms": 206173,
"explicit": false,
"external_urls": {
"spotify": "https://open.spotify.com/track/3skhDoiKAW73vulWCRsWjW"
},
"href": "https://api.spotify.com/v1/tracks/3skhDoiKAW73vulWCRsWjW",
"id": "3skhDoiKAW73vulWCRsWjW",
"is_local": false,
"name": "1000 Cigarettes",
"preview_url": "https://p.scdn.co/mp3-preview/157a6131e35c16519ef2a2b306523fc5c5f54dc0?cid=774b29d4f13844c495f206cafdad9c86",
"track_number": 2,
"type": "track",
"uri": "spotify:track:3skhDoiKAW73vulWCRsWjW",
"url_path": "http://localhost:5000/music/4tnnrgXBrdF0b4q3lZqL0v/1/2"
},
{
"disc_number": 1,
"duration_ms": 171226,
"explicit": false,
"external_urls": {
"spotify": "https://open.spotify.com/track/0u33BbRnsU2TCZyJaQ1NH3"
},
"href": "https://api.spotify.com/v1/tracks/0u33BbRnsU2TCZyJaQ1NH3",
"id": "0u33BbRnsU2TCZyJaQ1NH3",
"is_local": false,
"name": "Bounce (feat. Nore and Isis)",
"preview_url": "https://p.scdn.co/mp3-preview/2379a2e8849111c4a2faa1abddf273ba51711584?cid=774b29d4f13844c495f206cafdad9c86",
"track_number": 3,
"type": "track",
"uri": "spotify:track:0u33BbRnsU2TCZyJaQ1NH3",
"url_path": "http://localhost:5000/music/4tnnrgXBrdF0b4q3lZqL0v/1/3"
},
{
"disc_number": 1,
"duration_ms": 219333,
"explicit": false,
"external_urls": {
"spotify": "https://open.spotify.com/track/2REmc7SO87Ex6MtPQPafLl"
},
"href": "https://api.spotify.com/v1/tracks/2REmc7SO87Ex6MtPQPafLl",
"id": "2REmc7SO87Ex6MtPQPafLl",
"is_local": false,
"name": "Vuvuvu",
"preview_url": "https://p.scdn.co/mp3-preview/c996b13cf701175ce75d2a1ba4f1f8d54ff1b090?cid=774b29d4f13844c495f206cafdad9c86",
"track_number": 4,
"type": "track",
"uri": "spotify:track:2REmc7SO87Ex6MtPQPafLl",
"url_path": "http://localhost:5000/music/4tnnrgXBrdF0b4q3lZqL0v/1/4"
},
{
"disc_number": 1,
"duration_ms": 192853,
"explicit": false,
"external_urls": {
"spotify": "https://open.spotify.com/track/7d5Rp5q6XUegGhrIxEXja4"
},
"href": "https://api.spotify.com/v1/tracks/7d5Rp5q6XUegGhrIxEXja4",
"id": "7d5Rp5q6XUegGhrIxEXja4",
"is_local": false,
"name": "Heartbreaker",
"preview_url": "https://p.scdn.co/mp3-preview/5f280fbebded1b2ce5320e43f75ac32628ccae00?cid=774b29d4f13844c495f206cafdad9c86",
"track_number": 5,
"type": "track",
"uri": "spotify:track:7d5Rp5q6XUegGhrIxEXja4",
"url_path": "http://localhost:5000/music/4tnnrgXBrdF0b4q3lZqL0v/1/5"
},
{
"disc_number": 1,
"duration_ms": 243840,
"explicit": false,
"external_urls": {
"spotify": "https://open.spotify.com/track/07r3G29bZvODU5Lr0Nk6IZ"
},
"href": "https://api.spotify.com/v1/tracks/07r3G29bZvODU5Lr0Nk6IZ",
"id": "07r3G29bZvODU5Lr0Nk6IZ",
"is_local": false,
"name": "Fist Of God",
"preview_url": "https://p.scdn.co/mp3-preview/9453101e1568b713b0af6c1da4cfabd5d6664f03?cid=774b29d4f13844c495f206cafdad9c86",
"track_number": 6,
"type": "track",
"uri": "spotify:track:07r3G29bZvODU5Lr0Nk6IZ",
"url_path": "http://localhost:5000/music/4tnnrgXBrdF0b4q3lZqL0v/1/6"
},
{
"disc_number": 1,
"duration_ms": 206880,
"explicit": false,
"external_urls": {
"spotify": "https://open.spotify.com/track/66ZmwiF97Zk11pz5Jyfbwr"
},
"href": "https://api.spotify.com/v1/tracks/66ZmwiF97Zk11pz5Jyfbwr",
"id": "66ZmwiF97Zk11pz5Jyfbwr",
"is_local": false,
"name": "So Deep (feat. Jahmal of The Carps)",
"preview_url": "https://p.scdn.co/mp3-preview/6b62f7c210d42b266ac39064d90adf842db33465?cid=774b29d4f13844c495f206cafdad9c86",
"track_number": 7,
"type": "track",
"uri": "spotify:track:66ZmwiF97Zk11pz5Jyfbwr",
"url_path": "http://localhost:5000/music/4tnnrgXBrdF0b4q3lZqL0v/1/7"
},
{
"disc_number": 1,
"duration_ms": 208133,
"explicit": false,
"external_urls": {
"spotify": "https://open.spotify.com/track/4syNWEL0JzzybCfZ9MZHPv"
},
"href": "https://api.spotify.com/v1/tracks/4syNWEL0JzzybCfZ9MZHPv",
"id": "4syNWEL0JzzybCfZ9MZHPv",
"is_local": false,
"name": "Click Click (feat. E-40)",
"preview_url": "https://p.scdn.co/mp3-preview/62b6d3becb7fdabf6d0d706cf2ef273bdc477754?cid=774b29d4f13844c495f206cafdad9c86",
"track_number": 8,
"type": "track",
"uri": "spotify:track:4syNWEL0JzzybCfZ9MZHPv",
"url_path": "http://localhost:5000/music/4tnnrgXBrdF0b4q3lZqL0v/1/8"
},
{
"disc_number": 1,
"duration_ms": 231040,
"explicit": false,
"external_urls": {
"spotify": "https://open.spotify.com/track/5oBKd1jkmrZ6h9FbvdIzDS"
},
"href": "https://api.spotify.com/v1/tracks/5oBKd1jkmrZ6h9FbvdIzDS",
"id": "5oBKd1jkmrZ6h9FbvdIzDS",
"is_local": false,
"name": "Word Up (feat. Ghostface Killah)",
"preview_url": "https://p.scdn.co/mp3-preview/20d1b61b80ded729248f58cfbab178f92b17004a?cid=774b29d4f13844c495f206cafdad9c86",
"track_number": 9,
"type": "track",
"uri": "spotify:track:5oBKd1jkmrZ6h9FbvdIzDS",
"url_path": "http://localhost:5000/music/4tnnrgXBrdF0b4q3lZqL0v/1/9"
},
{
"disc_number": 1,
"duration_ms": 218453,
"explicit": false,
"external_urls": {
"spotify": "https://open.spotify.com/track/6RsIWxNzE82KdYztIT1IK1"
},
"href": "https://api.spotify.com/v1/tracks/6RsIWxNzE82KdYztIT1IK1",
"id": "6RsIWxNzE82KdYztIT1IK1",
"is_local": false,
"name": "Breakaway (feat. Jahmal of The Carps)",
"preview_url": "https://p.scdn.co/mp3-preview/8ea8912ae9bad9936090cee3ad85614142782d2c?cid=774b29d4f13844c495f206cafdad9c86",
"track_number": 10,
"type": "track",
"uri": "spotify:track:6RsIWxNzE82KdYztIT1IK1",
"url_path": "http://localhost:5000/music/4tnnrgXBrdF0b4q3lZqL0v/1/10"
},
{
"disc_number": 1,
"duration_ms": 191560,
"explicit": false,
"external_urls": {
"spotify": "https://open.spotify.com/track/2RYqwivWy9seoylZt6qUmH"
},
"href": "https://api.spotify.com/v1/tracks/2RYqwivWy9seoylZt6qUmH",
"id": "2RYqwivWy9seoylZt6qUmH",
"is_local": false,
"name": "1000 Cigarettes (feat. Freeway)",
"preview_url": "https://p.scdn.co/mp3-preview/0d38c708b8605d60fdaa386c790fe3a7be4cb0e1?cid=774b29d4f13844c495f206cafdad9c86",
"track_number": 11,
"type": "track",
"uri": "spotify:track:2RYqwivWy9seoylZt6qUmH",
"url_path": "http://localhost:5000/music/4tnnrgXBrdF0b4q3lZqL0v/1/11"
}
]
我尝试根据disc_number为1和track_number为4(第四个元素)的两个条件来获取上面json数组中的元素req.params.disc_number:1,req.params.track_number:4
var _ = require('underscore');
...
var track = _.where(album.tracks.items, {disc_number: req.params.disc_number, track_number: req.params.track_number});
console.log('track: ' + track)
track
什么也不返回([console] track:
),但它应该返回第四个元素(这个):
{ disc_number: 1,
duration_ms: 293600,
explicit: false,
external_urls:
{ spotify: 'https://open.spotify.com/track/616NBqU3gbjICFB1npf2vg' },
href: 'https://api.spotify.com/v1/tracks/616NBqU3gbjICFB1npf2vg',
id: '616NBqU3gbjICFB1npf2vg',
is_local: false,
name: 'Twilight Galaxy',
preview_url: null,
track_number: 4,
type: 'track',
uri: 'spotify:track:616NBqU3gbjICFB1npf2vg'}
当我传递 disc_number
和 track_number
时,我认为我不需要 parseInt()
。 _where
运算符以前在我有一个条件时可以工作
不知道出了什么问题
编辑1:我修复了从代码复制json时的拼写错误(现在有效),但它仍然不起作用
最佳答案
var data = [ { disc_number: 1,
duration_ms: 286013,
explicit: false,
external_urls:
{ spotify: 'https://open.spotify.com/track/0cahtHEywK64NSWqm2SDTi' },
href: 'https://api.spotify.com/v1/tracks/0cahtHEywK64NSWqm2SDTi',
id: '0cahtHEywK64NSWqm2SDTi',
is_local: false,
name: 'Help I\'m Alive',
preview_url: null,
track_number: 1,
type: 'track',
uri: 'spotify:track:0cahtHEywK64NSWqm2SDTi'},
{ disc_number: 1,
duration_ms: 257413,
explicit: false,
external_urls:
{ spotify: 'https://open.spotify.com/track/2uxLjFYEoQ7xsqfMPuwTQ9' },
href: 'https://api.spotify.com/v1/tracks/2uxLjFYEoQ7xsqfMPuwTQ9',
id: '2uxLjFYEoQ7xsqfMPuwTQ9',
is_local: false,
name: 'Sick Muse',
preview_url: null,
track_number: 2,
type: 'track',
uri: 'spotify:track:2uxLjFYEoQ7xsqfMPuwTQ9'},
{ disc_number: 1,
duration_ms: 222933,
explicit: true,
external_urls:
{ spotify: 'https://open.spotify.com/track/5lVXRLV1LgQgd7kUGt3Mae' },
href: 'https://api.spotify.com/v1/tracks/5lVXRLV1LgQgd7kUGt3Mae',
id: '5lVXRLV1LgQgd7kUGt3Mae',
is_local: false,
name: 'Satellite Mind',
preview_url: null,
track_number: 3,
type: 'track',
uri: 'spotify:track:5lVXRLV1LgQgd7kUGt3Mae'},
{ disc_number: 1,
duration_ms: 293600,
explicit: false,
external_urls:
{ spotify: 'https://open.spotify.com/track/616NBqU3gbjICFB1npf2vg' },
href: 'https://api.spotify.com/v1/tracks/616NBqU3gbjICFB1npf2vg',
id: '616NBqU3gbjICFB1npf2vg',
is_local: false,
name: 'Twilight Galaxy',
preview_url: null,
track_number: 4,
type: 'track',
uri: 'spotify:track:616NBqU3gbjICFB1npf2vg'},
{ disc_number: 1,
duration_ms: 245280,
explicit: false,
external_urls:
{ spotify: 'https://open.spotify.com/track/6JhUq57XpJeNMxboI4Ne3S' },
href: 'https://api.spotify.com/v1/tracks/6JhUq57XpJeNMxboI4Ne3S',
id: '6JhUq57XpJeNMxboI4Ne3S',
is_local: false,
name: 'Gold Guns Girls',
preview_url: null,
track_number: 5,
type: 'track',
uri: 'spotify:track:6JhUq57XpJeNMxboI4Ne3S'},
{ disc_number: 1,
duration_ms: 234586,
explicit: false,
external_urls:
{ spotify: 'https://open.spotify.com/track/4z2xy1UYMu70xCkWudeL96' },
href: 'https://api.spotify.com/v1/tracks/4z2xy1UYMu70xCkWudeL96',
id: '4z2xy1UYMu70xCkWudeL96',
is_local: false,
name: 'Gimme Sympathy',
preview_url: null,
track_number: 6,
type: 'track',
uri: 'spotify:track:4z2xy1UYMu70xCkWudeL96'},
{ disc_number: 1,
duration_ms: 286320,
explicit: false,
external_urls:
{ spotify: 'https://open.spotify.com/track/5dmGvCOyJi943jZgiMdmDC' },
href: 'https://api.spotify.com/v1/tracks/5dmGvCOyJi943jZgiMdmDC',
id: '5dmGvCOyJi943jZgiMdmDC',
is_local: false,
name: 'Collect Call',
preview_url: null,
track_number: 7,
type: 'track',
uri: 'spotify:track:5dmGvCOyJi943jZgiMdmDC'},
{ disc_number: 1,
duration_ms: 214440,
explicit: false,
external_urls:
{ spotify: 'https://open.spotify.com/track/3Ecg2M5kzSEzz6tR3fOg6g' },
href: 'https://api.spotify.com/v1/tracks/3Ecg2M5kzSEzz6tR3fOg6g',
id: '3Ecg2M5kzSEzz6tR3fOg6g',
is_local: false,
name: 'Front Row',
preview_url: null,
track_number: 8,
type: 'track',
uri: 'spotify:track:3Ecg2M5kzSEzz6tR3fOg6g'},
{ disc_number: 1,
duration_ms: 266840,
explicit: false,
external_urls:
{ spotify: 'https://open.spotify.com/track/7Apb2lh3o9cYUUHziHNuNN' },
href: 'https://api.spotify.com/v1/tracks/7Apb2lh3o9cYUUHziHNuNN',
id: '7Apb2lh3o9cYUUHziHNuNN',
is_local: false,
name: 'Blindness',
preview_url: null,
track_number: 9,
type: 'track',
uri: 'spotify:track:7Apb2lh3o9cYUUHziHNuNN'},
{ disc_number: 1,
duration_ms: 253693,
explicit: false,
external_urls:
{ spotify: 'https://open.spotify.com/track/73PtlKAy67oP9EGeK1fZPi' },
href: 'https://api.spotify.com/v1/tracks/73PtlKAy67oP9EGeK1fZPi',
id: '73PtlKAy67oP9EGeK1fZPi',
is_local: false,
name: 'Stadium Love',
preview_url: null,
track_number: 10,
type: 'track',
uri: 'spotify:track:73PtlKAy67oP9EGeK1fZPi'} ];
var track = _.where(data, {disc_number: 1, track_number: 10});
console.log(JSON.stringify(track))
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<div id="content"></div>
数据对象中存在语法错误。少了一个}。另外,fwiw,它不是有效的 JSON,因为 JSON 应该是字符串,但它仍然可以使用下划线。
关于javascript - underscorejs 其中运算符未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49523818/
我有这个数组: var ty = [ { "Language": "en-GB", "Section": "Sales", "ItemName": "Typ
我有一个对象列表“objlist”和一个 id 列表“idlist”。 var objlist = [{id:1, visible:true},{id:2, visible:false},{id:3,
我想做一个面包屑。我从后端获取数据,如下所示: var object = { "Department": { "DeptCode": null, "Descri
我有一个带有 bool 值的对象,一旦该值为true,我想测试我的对象中是否存在与函数相同的值,如果存在,那么我想调用该函数。我只需使用 JavaScript 即可做到这一点。 但是我正在寻找使用 u
我有这样的数据: var dates = [ {date: "2000-01-01", total: 120}, {date: "2000-10-10", total: 100},
假设我有一个长度为N的数组myArray。我想循环第 N 次。在纯 JavaScript 中,这将是: for (var i = 0; i < myArray.length; i++) {} 有没有办
我有一个来自数据库的对象数组,为了简洁起见,我想将其折叠。我已导入 underscore.js 来帮助完成此过程,但尝试使用提供的“groupBy”函数来压缩以下列表未成功: [ {ID:25
我有如下所示的 JSON 数组: [{ 'a': 1, 'b': 10, 'aa': { 'a': 11, 'ab': 110 } }, { 'a': 2, 'b': 2
这是album.tracks.items的json内容 [{ "disc_number": 1, "duration_ms": 220613, "exp
我有两个数组,balances 和 commits balances = [ {name: 'vacation', value: ''21}, {name: 'account', value: '2
我有一个组对象: {groupid1: "metadata", groupid2: "metadata"} 还有一组用户: [ { name: "something", groups: [
第一次使用下划线,我卡住了,找不到例子。 我的数据是: [{ "store_name": "Store 1", "franchisee_id": "id01",
只是存在一个 underscoreJs 方法来将具有某些属性的对象转换为具有关键属性的对象集合吗? 我的意思是,如果 underscorejs 中存在一个等效于此的简单方法: function obj
我正在尝试使用下划线独特的功能,但无法让它工作,这是我的测试代码: var foo = [ { "a" : "1" }, { "b" : "2" }, { "a" : "1" } ]; _.uniqu
有没有办法将数字列表分组为带下划线的数字区间? // Input: var arr = [0,1,2,8]; var interval = 3; // Output: // There are 3 n
在 AngularJS Controller 中有以下内容: $scope.initiatives = _.where($scope.initiatives, {i_status_id:'Open'}
我试图简单地用空字符串替换无效日期。我正在迭代对象数组,但每当我尝试使用 _.each() 时,我都会迷路。如果有人可以向我展示一种迭代列表中所有 fieldsToCheck 项目的方法,那就太棒了。
我正在 Underscore.js 中寻找一种方法来查找数组中数字之间的两个数字。 数字不能是 20 或列表中的任何数字。 我有一个可以运行的 Javascript 版本 var data = [
基本上我想使用 Lo dash 或 Underscore(最好是 lo-dash),但是对于我的系统来说,重要的是我不要全局加载变量并匿名使用它们。如果我不能使用 anon,那么至少将当前版本保留在页
我有一个对象数组。我想groupby & filter(remove) undefined object 、类别。为了更清楚地说明,请参阅下面的脚本: arrayFlatten = [ {
我是一名优秀的程序员,十分优秀!