在函数中使用具有其他函数生成的数字的对象

时间:2019-02-22 11:52:53

标签: javascript function for-loop element

我有一个函数,可以创建HTML以在选择框中显示位置,每个选择框上都带有一个勾号。想法是用户可以选中该框以选择位置,但是我很难设法以某种方式链接到2。

这是我创建HTML的for循环:

for (var i = 0; i < results.length; i++) {
    var place = results[i];
    var LocationString = "";
    var LocationName = place['name'];

    LocationString += `<div class="input-group">
    <span id="Location-checkbox-${[i]}" value=${[i]} class="input-group-addon">
    <input type="checkbox" aria-label="..." onclick="chooseSelection()">
    </span>
    <li id="Location-${[i]}" class="list-group-item"><strong>${LocationName}</strong><br>`;

    if (place['rating']) {
        var LocationRating = place['rating'];
        LocationString += `rating: ${LocationRating}<br>`;
    } else {
        var LocationRating = 'This place has no rating';
        LocationString += LocationRating;
    }

    if (place['user_ratings_total']) {
        var LocationUsers = place['user_ratings_total'];
        LocationString += `based on ${LocationUsers} reviews</li></div>`;
    } else {
        var LocationUsers = '</li></div>';
        LocationString += LocationUsers;
    }

    console.log(LocationString);
    htmlString += LocationString;

    var marker = createMarker(results[i]);
    currentMarkers.push(marker);
}

我正在使用chooseSelection()尝试链接2,然后将它们保存在字符串中以供稍后在结果页面中使用。

任何帮助将不胜感激!

0 个答案:

没有答案