0

我在右键单击树层次结构的任何文件夹时为菜单项“删除”定义了一个功能,以删除树的文件夹。但是单击它时,我收到以下错误消息“Store is null or not an object error in dojo”

谁能建议我如何更正此错误消息?我下面的函数有问题吗?

<ul dojoType="dijit.Menu" id="tree_menu" style="display: none;">   
      <li dojoType="dijit.MenuItem" data-dojo-props="disabled: false,
                                     onClick: function (evt){
                                     store.deleteById(selectedItemId);
                                     resetEditor();
                                 }",>Delete project</li></ul>

树形结构

- Main Project 1 
Sub Project 1_1  
Sub Project 1_2
 * sub Project 1_3 

+ Main Project 2 - 
Main Project 3 

Sub Project 3_1 - 
Sub Project 3_2 
Sub Project 3_2_1
4

1 回答 1

0

it appears that the onClick function is running in the MenuItem context, which means that in your onclick function, 'this' refers to the MenuItem widget instance.

To use your store variable in the onClick method, you can first reference it in your widget like this:

<ul dojoType="dijit.Menu" id="tree_menu" style="display: none;">   
  <li dojoType="dijit.MenuItem" data-dojo-props="disabled: false,
                                 _store: store,
                                 onClick: function (evt){
                                 _store.deleteById(selectedItemId);
                                 resetEditor();
                             }",>Delete project</li></ul>

Or you can reference your global store object in the window context:

<ul dojoType="dijit.Menu" id="tree_menu" style="display: none;">   
  <li dojoType="dijit.MenuItem" data-dojo-props="disabled: false,
                                 onClick: function (evt){
                                 window.store.deleteById(selectedItemId);
                                 resetEditor();
                             }",>Delete project</li></ul>
于 2013-10-14T09:05:33.513 回答