On my page I have a section containing UL's and each UL gets populated from an array of strings

在我的页面上,我有一个包含UL的部分,每个UL都是从字符串数组中填充的

dealers = [{
    title   : "Brecksville",
    address : "8383 Chippewa Rd.,",
    locale  : "Brecksville, Ohio - 44141",
    phone   : "(440) 740-0535",
    location: {lat: 41.32134300, lng: -81.62338300}
}];

For brevity I only show one of the strings in the array of strings...

为了简洁,我只显示字符串数组中的一个字符串……

This string is populated into the UL like so...

这个字符串像这样填充到UL中…

function populatDealerSummaryList(select, dealers) {
    $listSelector = $("#dealersList"); //The Dealer Summary List

    $.each(dealers, function (i, obj) {
        $listSelector.append(
            "<ul class='dealer-summary-list'>" +
            "<li class='dealerName'>" + obj.title + "</li>" +
            "<li class='dealer-summary-listItem'>" + obj.address + "</li>" +
            "<li class='dealer-summary-listItem'>" + obj.locale + "</li>" +
            "<li class='dealer-summary-listItem'>" + obj.location + "</li>" +
            "<li class='dealer-summary-listItem'>" + obj.phone + "</li>" +
            "</ul>");
    });
}

above...the latitude and longitude are represented by obj.location...

以上……纬度和经度由object .location…

the problem is...the lat long only renders as [object, object]

问题是……lat只显示为[object, object]

I'm not sure how to pass it correctly to get it to render...please help

我不知道如何正确地传递它以使它呈现…请帮助

2 个解决方案

#1


4

You get this result because Object method toString() return this output string "[object Object]";

得到这个结果是因为Object方法toString()返回输出字符串“[Object]”;

You can write like this:

你可以这样写:

...>" + JSON.stringify(obj.location) + "<...

Or

...>" + obj.location.lat + ', ' + obj.location.lng + "<...

Look at JSFiddle. There are both approaches

看看JSFiddle。有两种方法

更多相关文章

  1. $.each遍历JSON字符串和 Uncaught TypeError: Cannot use 'in' o
  2. 如何在python中使用命名组和datadict从正则表达式模式中组合字符
  3. 字符串压缩 牛客网 程序员面试金典 C++ Python
  4. Python 用hashlib求中文字符串的MD5值
  5. 将字节列表转换为字节字符串
  6. [D]用python提取多段字符串该怎么写正则表达式。
  7. 如何用位于括号外的逗号分隔字符串?
  8. 用于搜索和替换大字符串的最快Python方法
  9. python 字符串操作

随机推荐

  1. [置顶] android 幻灯片效果之小方块渐入
  2. 如何成为一个更好的Android开发者:30+个
  3. Android和设计模式:策略模式
  4. 字节跳动正式启动2021届秋季校招!这份字节
  5. Android——进程与线程
  6. 【幻灯片分享】Android音频口数据通信开
  7. 且谈Android内存溢出
  8. 里程碑2给Android市场造成哪些影响
  9. Android 架构简介
  10. android 根据设置的日期获取星期几