我正在尝试使用MagicSuggest和一个php查询来构建一组链接/链接的多个选择框。因此,首先,我构建了一个MagicSuggest框,其中包含一个函数,用于当ms1被更改时:
$(document).ready(function() {
var ms1 = $('#ms1').magicSuggest({
data: 'datams1.php',
displayField: 'name' });
$(ms1).on('selectionchange', function(event, combo, selection){
run(selection);});
});然后,通过运行一个返回json对象的php查询来构建一个新的MagicSuggest框:
function run(country) {
$.getJSON("query.php", { id: country[0].id}, callbackFuncWithData );
}
function callbackFuncWithData(region) {
var ms2 = $('#ms2').magicSuggest({
data: region,
displayField: 'name'
});
}一旦我做了一个初始的选择,这就可以了,但是如果我更改了选择,它就不会更新。我已经检查并在"callbackFuncWithData“中生成了一个更新的"region”json对象。因此,我可能需要刷新/重新加载#ms2对象。
我的问题是:
谢谢!
发布于 2014-05-14 10:37:23
发布于 2015-04-12 18:45:34
此代码使用相同的数据生成两个链接组合,但其中一个显示“名称”字段,另一个显示"name1“字段。
function reflectSelection(ms1, ms2){
var val = parseInt(ms1.getValue());
var val1 = parseInt(ms2.getValue());
if(!isNaN(val)){
if(val != val1){
ms2.clear(true);
ms2.setSelection(ms1.getSelection());
}
}
else
{
ms2.clear(true);
}
}
var msName = $('#ms-onselectionchange').magicSuggest({
maxSelectionRenderer: function(){ return ''; },
useTabKey: true,
noSuggestionText: '',
strictSuggest: true,
maxSelection: 1,
allowFreeEntries: false,
placeholder : '',
data: [{'id':0, 'name':'Paris', 'name1':'Paris5'}, {'id':1, 'name':'New York', 'name1':'New York5'}],
});
var msName1 = $('#ms-onselectionchange1').magicSuggest({
maxSelectionRenderer: function(){ return ''; },
useTabKey: true,
noSuggestionText: '',
displayField: 'name1',
strictSuggest: true,
maxSelection: 1,
allowFreeEntries: false,
placeholder : '',
data: [{'id':0, 'name':'Paris', 'name1':'Paris5'}, {'id':1, 'name':'New York', 'name1':'New York5'}],
});
$(msName).on('selectionchange', function(e,m){
reflectSelection(msName, msName1);
});
$(msName1).on('selectionchange', function(e,m){
reflectSelection(msName1, msName);
});https://stackoverflow.com/questions/18354335
复制相似问题