2012-02-05 82 views
2

我一直在使用此教程的IBM教程。Dojo:在添加新组后,无法更新下拉列表

http://www.ibm.com/developerworks/web/tutorials/wa-dojotoolkit/section6.html

我已经做得非常好,到目前为止,但我似乎无法得到下拉列表填充新的组条目。即使原来的代码不起作用。

//Refresh the data store for the groups dropdown (in case groups added, edited or deleted) 
function refreshGroupDropDown() { 
    var theStore = dijit.byId("edit_contact_group").store; 
    theStore.close(); 
    theStore.url = "data/groups.php"; 
    theStore.fetch(); 
} 

谢谢!

更新:仍然有麻烦。我在下面尝试了这一点,仍然没有。当用户打开编辑联系人窗口或新的联系人窗口时,会调用refreshGroupDropDown()函数。

//Refresh the data store for the groups dropdown (in case groups added, edited or deleted) 
function refreshGroupDropDown() { 
    var new_store = new ItemFileReadStore({url: 'data/groups.php' , clearOnClose: true}); 
    var theStore = dijit.byId("edit_contact_group"); 
    theStore.store = new_store; 
    theStore.close(); 
    theStore.fetch(); 

} 

    //Clears the "Edit Contact" form, sets it up for adding a new contact 
function newContact() { 
    var contact = contactsGrid.selection.getSelected()[0]; 
    refreshGroupDropDown(); 
    dojo.byId("edit_contact_real_id").value = ""; 
    dojo.byId("edit_contact_id").value = "[NEW]"; 
    dijit.byId("edit_contact_group").reset(); 
    dijit.byId("edit_contact_first_name").reset(); 
    dijit.byId("edit_contact_last_name").reset(); 
    dijit.byId("edit_contact_email_address").reset(); 
    dijit.byId("edit_contact_home_phone").reset(); 
    dijit.byId("edit_contact_work_phone").reset(); 


    dijit.byId("editContactDialog").set("title", "New Contact"); 
    dijit.byId("editContactDialog").show(); 
} 

    //Process the adding of a new group to the database 
function doNewGroup(e) { 
    e.preventDefault(); 
    e.stopPropagation(); 
    dojo.byId("new_group_ajax").value = "1"; 
    if(this.isValid()) { 
     dojo.xhrPost({ 
      form: this.domNode, 
      handleAs: "json", 
      load: function(data) { 
       if(data.success) { 
        okDialog.set("title","Group created successfully"); 
        okDialogMsg.innerHTML = "The group <strong>"+data.name+"</strong> was created successfully."; 

        groupsStore.newItem({"id":data.id.toString(),"name":data.name}, {"parent": groupsModel.root, "attribute":"groups"}); 
        groupsStore.save(); 

        newGroupDialog.hide(); 
        okDialog.show(); 
       } 
       else { 
        okDialog.set("title","Error creating group"); 
        okDialogMsg.innerHTML = data.error; 
        okDialog.show(); 
       } 
      }, 
      error: function(error) { 
       okDialog.set("title","Error creating group"); 
       okDialogMsg.innerHTML = error; 
       okDialog.show(); 
      } 
     }); 
    } 
} 

希望这有助于!我是初学者,所以任何帮助表示赞赏。

回答

2

我想通了!问题在于index.html。组的下拉列表的输入标记如下所示

<input dojoType="dijit.form.FilteringSelect" name="move_contact_new" store="groupsStore" searchAttr="name" query="{type:'node'}" id="move_contact_new" required="true" style="margin-bottom: 6px" /> 

查询属性从未正确设置。一旦我删除了查询=“{类型:'节点'}”组添加,编辑或删除组后重新填充组。

初学者问题的初学者答案。

希望这可以帮助任何初学者。

0

根据您发布的内容,我看到的唯一问题是使用行var theStore = dijit.byId("edit_contact_group").store;,因为它不会创建数据存储。您需要确保您还包括诸如`var edit_contact_group = new dojo.data.ItemFileReadStore();或其他等效物。不过,你是否已经使用dojo.connect()将refreshGroupDropDown()函数连接到了适当的事件('onclick'或其他)?你有没有使用dojo.ready加载函数refreshGroupDropDown()?即。 dojo.ready(function(){refreshGroupDropDown();});那些永远是第一个想到的东西...