
我正在使用select2在下拉列表中显示ajax结果但是当我将数据追加到select2时它显示错误
TypeError: b is undefined
Run Code Online (Sandbox Code Playgroud)
JS代码
var baseurl = $("#baseurl").val();
$(".myselect").select2({
placeholder: "Select a inspector",
allowClear: true,
ajax: {
url: baseurl + '/admin/getdata',
dataType: 'json',
type: "GET",
quietMillis: 50,
data: function (term) {
return {
term: term.term
};
},
results: function (data) {
var myResults = [];
$.each(data, function (index, item) {
myResults.push({
'id': item.id,
'text': item.firstname
});
});
return {
results: myResults
};
}
}
});
Run Code Online (Sandbox Code Playgroud)
term.term包含下拉搜索框中输入文本的值.
HTML
<select class="myselect" style="width: 50% !important">
<option></option>
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option>
<option …Run Code Online (Sandbox Code Playgroud) 在线帮助使用带有capybara的select2(参见下面的链接),但就我在select2下拉字段中看到的情况而言,没有任何帮助.我尝试了各种各样的事情,包括在以下情况下尝试填写字段:js => false(使用某些内容find(:xpath, "//input[@id='product_manufacturer_id']").set "Test product manufacturer")或其他select2字段的解决方案的变体(请参阅下面给出的链接).到目前为止,没有什么对我有用.
关于我的配置的说明:
f.association......).特别是,ProductManufacturer实例has_many与产品有关系.ProductManufacturer与查询文本匹配的实例(即您在搜索字段中键入的文本)动态填充.如果有必要了解我如何实施工厂:
这是我的工厂文件:
factory :product do
name "Test product"
url { Faker::Name.name.parameterize }
access_level 1
product_manufacturer
end
factory :product_manufacturer do
name "Test product manufacturer"
factory :product_manufacturer_with_product do
transient do
products_count 1
end
after(:create) do |product, evaluator|
create_list(:product,
evaluator.products_count,
product: product)
end
end
end
Run Code Online (Sandbox Code Playgroud)
然后,在测试开始之前,我运行:
@product_manufacturer = create(:product_manufacturer)
Run Code Online (Sandbox Code Playgroud)
我的最新尝试: 我的帮助方法(适用于我的其他select2字段):
def select2_choose(id, options)
page.execute_script "$('#{id}').trigger('keydown').val('{options[:query]}').trigger('keyup');"
find(".select2-result-label", :text => options[:choose]).click …Run Code Online (Sandbox Code Playgroud) 我正在使用select2插件,因为我想向选项“数据值”添加自定义属性。
$('select').select2({
data: [
{
id: 'value',
text: 'Text to display'
},
]
});
Run Code Online (Sandbox Code Playgroud)
如果在上述代码中添加“数据值”,它将不会显示该选项。有什么办法可以做这样的事情。我正在使用4. * select2插件
有什么方法可以按名称对由select2生成的列表进行排序?我有一些代码:
var dataUser = [{
"id": "5",
"text": "BTest"
}, {
"id": "2",
"text": "ATest"
}, {
"id": "8",
"text": "CTest"
}, {
"id": "13",
"text": "DTest"
}];
$("#mylist").select2({
data: dataUser,
templateResult: function(data) {
return data.text;
},
sorter: function(data) {
return data.sort();
}
});
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/oe9retsL/4/
此列表按ID排序,但我想按文本排序。
我一直在阅读nodejs如何使用libuv来执行异步I/O. 阅读更多关于它的感觉让我觉得它几乎听起来像select(2)和epoll.
所以,我的问题是,如果我使用libuv(通过节点)是内部我使用select(2)或epoll.
libuv是unix中的select(2)和epoll系统调用的包装吗?
我无法让 select2 与我的 wrapbootstrap (Inspinia) 主题一起使用。
这些选项出现在我的模态“下方”,使它们无法选择(请参见下面的屏幕截图)。我认为 Select2 创建了一堆阻碍了它的包装器。我该如何解决?当我检查元素时,这就是我所看到的:
<div class="form-group">
<label>Variant SKU</label>
<select name="variant_sku_id" id="variant_sku_id" class="variant_sku_id form-control select2-hidden-accessible" tabindex="-1" aria-hidden="true">
<option value="1">option1</option>
<option value="2">option2</option>
</select>
<span class="select2 select2-container select2-container--default select2-container--below select2-container--open" dir="ltr" style="width: 100px;">
<span class="selection">
<span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="true" tabindex="0" aria-labelledby="select2-variant_sku_id-container" aria-owns="select2-variant_sku_id-results" aria-activedescendant="select2-variant_sku_id-result-3g9n-1">
<span class="select2-selection__rendered" id="select2-variant_sku_id-container" title="option1"</span>
<span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span>
</span>
</span>
<span class="dropdown-wrapper" aria-hidden="true"></span>
</span>
</div>
Run Code Online (Sandbox Code Playgroud)
我正在使用 Select2 和 Ajax 来加载远程数据(建议)。
一切正常,但有一个问题:当用户只输入空格(按空格键)时 - 正在发送 Ajax 请求。
我怎样才能防止这种情况?另外,我想在发送之前修剪条款。
$(".js-data-example-ajax").select2({
placeholder: "Select... ",
minimumInputLength: 3,
ajax: {
url: "/my-site/tags",
dataType: 'json',
data: function (params) {
return {
q: params.term
};
},
processResults: function (data) {
return {
results: data
};
},
cache: true
}
Run Code Online (Sandbox Code Playgroud)
编辑:
我忘了提到我已经尝试过这样的事情:
data: function (params) {
if (params.term.trim().length < 2) {
return;
}
return {
q: $.trim(params.term)
};
},
Run Code Online (Sandbox Code Playgroud)
并且仍然发送 GET (Ajax) 请求。
使用Select2(https://select2.github.io/examples.html)进行多值选择框时,您可以从下拉列表中切换选定的值.有什么方法可以防止这种行为吗?因此,您只能通过单击旁边的X来删除所选项目.
所有帮助非常感谢.
我select2在我的probject 中使用插件(最新版本4.0.2)进行自动完成。我发现select2只能应用于选择控件。主要问题是文本输入作为此控件的第一个选项放置(参见下面的 img)。
有什么方法可以放置文本输入而不是选择控件(如 typeahead 插件)?
一些截图(其实你可以在这里试试)
折叠(您只能在此处看到带有选定选项的标准选择 html 控件)
展开(文本输入位置作为选择控件的第一个选项,如果选择折叠则隐藏文本输入)
Typeahead(适用于直接输入文本,在页面始终显示的第一行输入查询文本)
在 yii2 的 select2 小部件中,我们如何从小部件对控制器中的函数进行 ajax 调用:场景是我需要为表创建自定义 ID,该 ID 取决于两个下拉值和 select2 的选择事件下拉我需要获取记录并构造 ID 并将新创建的 ID 的值放入提交的表单中。我只是在从 select2 下拉小部件进行 ajax 调用时遇到问题