dijit.form.Select不会以编程方式设置值 [英] dijit.form.Select won't set value programmatically
问题描述
var bcntryval =<?= $ this-> billingContact-> countryId;?> ;;
var countryStore;
函数onBillingShow(){
if(countryStore)countryStore.close();
countryStore = new dojo.data.ItemFileReadStore({url:'CartUtilities.php?action = getcountries'});
dijit.byId(bcntry)。setStore(countryStore,bcntryval); //不设置值!但是设置商店
dijit.byId(bcntry)。attr('value',String(bcntryval)); //不设置
dijit.byId(bcntry)。set('value',bcntryval)); //也没有这个!
}
我的bcntry小部件的标记如下:
< td>< input data-dojo-type =dijit.form.Selectstyle =width:10em; data-dojo-props =sortByLabel:false,maxHeight:' - 1'data-dojo-id =bcntryid =bcntryname =bcntry/>
我投入了大量的时间学习dojo。当它的工作很好,但文档离开很多,希望!
我也看到与dijit.form.FilteringSelect类似的问题。这也忽略了通过javaScript设置值。
我也试过这个代码的完全编程版本。我得出结论,当您从商店选择时,设置值不起作用。
这个DID工作,但不是动态的。
< div name =scntrydata-dojo-type =dijit.form.Selectdata-dojo-props =maxHeight:' - 1',sortByLabel:falsevalue =<?= $ this-> shippingContact-> countryId;?& >
<?php foreach($ this-> countryList as $ c):?>
< span value =<?= $ c-> id;?>><?= $ c-> name;?>< / span>
<?php endforeach;?>
< / div>
看看这里,我相信这样做想要以Dojo的方式:
设置dijit.form.Select widget的值(选择的选项)
如果没有,你可以总是使用实际的dom选择对象,并使用直接的Javascript:
如何使用javascript编程设置select box元素的值?
I have a dynamic dojo form in which I have a dijit.form.Select whose selected value I have tried to set dynamically through various ways. I get the select widget to load and show the data, but it always ignores my every attempt. I am using dojo 1.7.
var bcntryval = <?= $this->billingContact->countryId;?>;
var countryStore;
function onBillingShow() {
if (countryStore) countryStore.close();
countryStore = new dojo.data.ItemFileReadStore({url: 'CartUtilities.php?action=getcountries'});
dijit.byId("bcntry").setStore(countryStore, bcntryval); // does not set value! but does set the store
dijit.byId("bcntry").attr('value', String(bcntryval)); // doesn't set the value either
dijit.byId("bcntry").set('value', bcntryval)); // nor does this!
}
My markup for the bcntry widget is as follows:
<td><input data-dojo-type="dijit.form.Select" style="width: 10em;" data-dojo-props="sortByLabel:false, maxHeight:'-1'" data-dojo-id="bcntry" id="bcntry" name="bcntry" />
I've invested a fair amount of time on learning dojo. When it works its nice, but the docs leave a lot to be desired! I am also seeing a similar problem with the dijit.form.FilteringSelect. That also ignores setting the value via javaScript. I've also tried completely programmatic versions of this code. I have come to the conclusion that setting the value just doesn't work when you're selecting from a store. This DID work, but its not dynamic.
<div name="scntry" data-dojo-type="dijit.form.Select" data-dojo-props="maxHeight:'-1',sortByLabel:false" value="<?= $this->shippingContact->countryId;?>" >
<?php foreach($this->countryList as $c):?>
<span value="<?= $c->id;?>"><?= $c->name;?></span>
<?php endforeach;?>
</div>
Take a look here, I believe this does what you want in the Dojo way:
Setting the value (selected option) of a dijit.form.Select widget
If not, you can always just use the actual dom selection object and use straight Javascript:
How do I programatically set the value of a select box element using javascript?
这篇关于dijit.form.Select不会以编程方式设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!