通过阵列预输入引导 [英] Pass array to typeahead Bootstrap

查看:145
本文介绍了通过阵列预输入引导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过JSON将值传递到源的数组:引导的键盘缓冲插件选项

I'm trying to pass via json an array of values to the source: option of Typeahead plugin of Bootstrap.

下面是我简单的code: 的jsfiddle

Here is my simple code: JsFiddle

我有一个 JSON 对象,我想只是值id传递给来源:阵列

I have a JSON object and I'd like to pass just the value id to the source: array

我在做什么错了......我试过很多东西。

What I'm doing wrong... I tried many things.

推荐答案

Twitter的预输入期待一个Javascript数组类型。所以,你需要使用 JSON.parse(myJSONObject)您的JSON对象转换为合法的数组。然而,预输入也期待一个字符串数组,数组没有数组...所以,问题是 - ?这些阵列的参数是你想在预输入显示

Twitter's typeahead is expecting a Javascript array type. So, you'll need to convert your JSON object to a legitimate array using JSON.parse(myJSONObject). However, typeahead is also expecting an array of strings, not array of arrays... So, the question is - which parameter of these arrays are you trying to show in the typeahead?

{
    "id":"2",
    "pid":"0",
    "type":"Group",
    "code":"g",
    "status":"1"
}

它看起来像你的丘壑功能隔离 ID 参数。如果是这样的参数,你想预输入,显示,简单点 X 。结帐这个修改后的jsfiddle:

It looks like your vals function is isolating the id parameter. If that's the parameter you'd like typeahead to show, simply point source to x. Checkout this modified jsFiddle:

  • http://jsfiddle.net/365Sf/

这篇关于通过阵列预输入引导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆