我想选择长度,但是它是字符串形式。与attribs.length相似,但未返回任何内容。

attribs: {
    "length": ""4"",
    "nightride": "null"
}


我曾尝试将其拆分并重新加入,但是无论哪种方式我都无法获得想要的东西。
我也尝试过attribs [length]和attribs [“ length”]但无济于事。

这是它的主要块:



{
    places: [
{
    city: "Boise",
    state: "Idaho",
    country: "United States",
    name: "Elk Meadows",
    parent_id: null,
    unique_id: 1637,
    directions: ""From Boise's north end (at the intersection of Hill and Bogus Basin roads), travel north up Bogus Basin road about 16.5 miles.the pavement ends at lower (main)parking lot near Bogus Creek Lodge. Proceed on the Boise Ridge Rd. Where the sandy surface turns to pavement as it leavesthe main ridge rd.and splitsright, up through a series of switch backs to the Pioneer Lodge milage starts here",
    lat: 43.764,
    lon: -116.10324,
    description: null,
    date_created: null,
    children: [ ],
    activities: [{
        name: "Elk Meadows",
        unique_id: "1-118",
        place_id: 1637,
        activity_type_id: 5,
        activity_type_name: "mountain biking",
        url: "http://www.singletracks.com/item.php?c=1&i=118",
        attribs: {
            "length": ""4"",
            "nightride": "null"
        },
        description: "ride east up behind Pioneer Lodge past the tennis courts on your left. the double track becomes more defined",
        length: 4,
        activity_type: {
            created_at: "2012-08-15T16:12:35Z",
            id: 5,
            name: "mountain biking",
            updated_at: "2012-08-15T16:12:35Z"
        },
        thumbnail: "http://images.singletracks.com/2010/11/Elk-Meadows-on-the-Ranier-0.jpg",
        rank: null,
        rating: 3
      }
    ]
 },





这是我为获取该数据所做的尝试:

{{ result.activities[0].attribs["length"] }}

最佳答案

如果attribs是实际的javascript对象,并且您想要attribs.length的数值

var x = parseFloat(attribs.length.replace(/"/g,''));

10-07 19:25