Javascript 我正在从html调用jquery函数,选择并访问jquery函数中的某个对象。但它是不明确的

Javascript 我正在从html调用jquery函数,选择并访问jquery函数中的某个对象。但它是不明确的,javascript,jquery,Javascript,Jquery,这是我的jquery函数 <script type="text/javascript"> $('#branddrop').change(function getModels(){ console.log('entered') brand = $(this).val(); console.log(brand); console.log("http://localhost:8006/api/models/" + St

这是我的jquery函数

<script type="text/javascript">
    $('#branddrop').change(function getModels(){
        console.log('entered')
        brand = $(this).val();
        console.log(brand);
        console.log("http://localhost:8006/api/models/" + String(brand['name']));
        $.get("http://localhost:8006/api/models/", 
        function(data) {
            var models = $('#model');

            models.empty();

            $.each(data, function(i, value) {       
                models
                    .append($("<option></option>")
                    .attr("value",value.name)
                    .text(value.name)); 
            });

        });
    });
</script>

但是当控制台中的
品牌['name']
我没有定义。

看起来品牌变量包含字符串值
'{“id”:5,“name”:“LeEco”,“created_at”:null,“updated_at”:null}

您可能需要将字符串解析为对象,如下所示:

var brandObj = JSON.parse(brand);
brandObj['name'] // should work
var brandObj = JSON.parse(brand);
brandObj['name'] // should work