以 JSON 作为文本的传单弹出窗口

leaflet pop-up with JSON as text

出于调试目的,我希望我的标记有一个弹出窗口,其中包含 json。

值类似于:

var CarState= {
    "height" : 6.2,
    "width" : 7.3,
    "length" : 9.1,
    "color" : {
        "r" : 255,
        "g" : 200,
        "b" : 10
    }
}

但这不起作用,我得到的只是一个截断的弹出窗口。 CarState 的内容不断变化,但相同的 属性 包在那里。

注意:self 指的是这段代码所在的 AMD 模块。我不使用它,因为你会遇到麻烦。 self.pop 是一个包含 L.PopUp

的变量
this.update = function () {
    var text = "<p>" + JSON.stringify(CarState) + "</p>";
    self.pop.setContent(text);
    self.pop.update();
}

这是它的样子:

这里是 Chrome 说的是弹出窗口 div 大小:

好的,这对我有用。不完全确定是什么问题。

    this.update = function () {
        var text = "<pre><code>" + JSON.stringify(CarState, null, '\t') + "</code></pre>";
        theCar.setPopupContent(text);
        theCar.update();
        theCar.setLatLng(L.latLng(CarState.lat, CarState.lon));
        theMap.panTo(L.latLng(CarState.lat, CarState.lon));
    }