gpt4 book ai didi

javascript - Jquery 多选插件与meteor

转载 作者:行者123 更新时间:2023-12-03 09:55:45 25 4
gpt4 key购买 nike

我正在将 jquery multiSelect 插件 ( http://harvesthq.github.io/chosen/ ) 与 Meteor 一起使用。效果很好。当选项列表动态更改时,它会在选项列表中显示旧的相同值。

<template name="testDynamicSelect">
<select class="chosen-select">
{{#each selectList}}
<option style="width: 300px">{{this}}</option>
{{/each}}
</select>
</template>

帮助者

Session.set('selectList',['delhi','pune','chandigarh']);
Session.set('run',true);
Template.testDynamicSelect.helpers({
selectList:function(){
return Session.get('selectList')
}
});

Template.testDynamicSelect.rendered = function(){
var instance = this;
instance.autorun(function(){
if(Session.get('run')){
var config = {
'.chosen-select': {},
'.chosen-select-deselect' : {allow_single_deselect:true},
'.chosen-select-no-single' : {disable_search_threshold:10},
'.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
'.chosen-select-width' : {width:"95%"}
}

for (var selector in config) {
$(selector).chosen(config[selector]);
}
Session.set('run',false);
console.log('run select ');
}
});
}

现在在控制台中,当我键入时

Session.set('selectList',['delhi','pune','chandigarh','bangalore']);
Session.set('run',true);

我没有得到更新值“bangalore”。

最佳答案

您的 .rendered() 仅在模板呈现时运行一​​次,在模板再次呈现之前,它不会对 run session 变量中的更改使用react.

您需要更新模板帮助程序中的菜单,以使其对地名数组中的更改使用react。

关于javascript - Jquery 多选插件与meteor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30747500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com