根据第一个 - ZF和dojo填充第二个过滤选择

时间:2011-04-30 11:03:59

标签: zend-framework dojo

我从第一个FS(filteringSelect)返回的响应json字符串与第二个的内容,但我不能使它加载它。我已尝试使用store.clearOnClose,但它不起作用,我的javascript是有效的。你怎么做到这一点 ? 这是我的表单中的代码,带有2个filteringSelects:

$category=new Zend_Dojo_Form_Element_FilteringSelect("category");
    $category->setLabel("Category");
    $category->setAttrib("id","category")
            ->setAttrib("onChange","
                                    var cat=dojo.query('#category ')[0].value;

                                   dojo.xhrPost({
                                            url: 'getsubcategories',
                                           handleAs: 'text',
                                           content: { category:cat } ,
                                            load: function(data, ioArgs) {
                                                      var store=subCatStore.store;
                                                      store.data=data;
                                                      store.close()
                                            },
                                           error: function(data,ioArgs) {
                                                   if(typeof data== 'error'){
                                                        console.warn('error');
                                                        console.log(ioArgs);
                                                     }
                                                 }


                                    });
                                   "
    );
    $category->setOptions(array(
        "autocomplete"=>false,
        "storeId"=>"category",
        "storeType"=>"dojo.data.ItemFileReadStore",
        "storeParams"=>array("url"=>"getcategories"),
        "dijitParams"=>array("searchAttr"=>"name")
                          )
                          )
            ->setRequired(true);
    $subCategory=new Zend_Dojo_Form_Element_FilteringSelect("subCategory");
    $subCategory->setLabel("Sub Category")
            ->setAttrib("id","subCategory");
    $subCategory->setOptions(array(
        "autocomplete"=>false,
        "storeId"=>"subCatStore",
        "jsId"=>"subCatStore",
        "storeType"=>"dojo.data.ItemFileReadStore",
        "storeParams"=>array("clearOnClose"=>true,"url"=>"getsubcategories"),
        "dijitParams"=>array("searchAttr"=>"name")))
            ->setRequired(true);

我在网上红了,这是做到这一点的方法,获得第二个下拉菜单的元素 第1次更改时传递值。我错了吗 ? Tnx引起你的注意。

1 个答案:

答案 0 :(得分:1)

我不知道zf,但这就是我们在js中的表现:

new dijit.form.FilteringSelect({
id: "country",
name: "country",
store: countryStore,
required: false,
onChange: function(country) {
    dijit.byId('state').query.countryId = country ;
},
searchAttr: "name"
},"country");