douluanji8752 2015-11-12 22:09
浏览 23

php json数据不起作用

I've created an array using php which I've then json encoded

$json_array =  json_encode($newarray);

In my jquery, the encoded array seems to be formed OK (i think??) but when I try and use the json data - nothing happens? I'm expecting the textbox to autocomplete.

The funny thing is - it works if I use arraytxt2, but not arraytxt1 (the one created via json_encode).

Any ideas as to why arraytxt1 is not working?? Thanks in advance.

$(document).ready(function () {
    var arraytxt1 = [{
        "equipmentid": "1",
        "equipmentmake": "Baxi"
    }, {
        "equipmentid": "2",
        "equipmentmake": "Baxi"
    }];

    var arraytxt2 = [{
        "id": "1",
        "label": "aa"
    }, {
        "id": "2",
        "label": "bb"
    }, {
        "id": "3",
        "label": "bbbb"
    }, {
        "id": "4",
        "label": "abab"
    }, {
        "id": "5",
        "label": "cab"
    }];

    $("#txt1").autocomplete({
        source: arraytxt1,
        minLength: 1,
        select: function (event, ui) {
            $("#txt2").val(ui.item.equipmentid);
        }
    });
});
  • 写回答

1条回答 默认 最新

  • douhan8581 2015-11-13 01:12
    关注

    The correct keys for autocomplete's array objects are label and value. The value property might not be needed in your case.

    https://api.jqueryui.com/autocomplete/#option-source

    Try:

    var arraytxt1 = [{
        "equipmentid": "1",
        "label": "Baxi"
    }, {
        "equipmentid": "2",
        "label": "Baxi"
    }];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看