我是Dojo Toolkit的新手。我收到了错误
Tried to register widget with id=myButton but that id is already registered
每当我尝试加载dojo内容两次时(意味着我通过jQuery.Load将HTML内容加载到容器div中)。有没有办法在dojo中取消注册已注册的小部件?我已经看过一些例子,但我并没有真正让它们发挥作用。
我的按钮:
<button dojoType="dijit.form.Button" id="myButton">button</button>
答案 0 :(得分:37)
如果您要取消注册特定小部件,可以使用他们的destroy()
或destroyRecursive()
方法。第二个销毁你正在销毁的小部件内的任何小部件(即在表单小部件上调用destroyRecursive也会销毁所有表单组件)。
在您的情况下,听起来您最好的选择是在jQuery.load
-
var widgets = dijit.findWidgets(<containerDiv>);
dojo.forEach(widgets, function(w) {
w.destroyRecursive(true);
});
上述代码将取消注册<containerDiv>
中的所有小部件,和保留其关联的DOM节点。要销毁DOM节点,请将false
传递给destroyRecursive
。
参考:
http://dojotoolkit.org/api/1.3/dijit/_Widget/destroyRecursive
答案 1 :(得分:10)
基于http://bugs.dojotoolkit.org/ticket/5438,我发现了一种破坏道场小部件的充分方法:
dijit.registry.forEach(function(w){
w.destroy();
});
答案 2 :(得分:5)
这对我有用:
dijit.byId( 'myButton' ).destroy( true );
答案 3 :(得分:1)
我认为您最好从按钮中删除ID并使用附加点访问它。你基本上会做 public class ImageAdapter extends BaseAdapter
{
private Context context;
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.get_all_comm_list_view, null);
}
ImageButton cmdDelete = (ImageButton) convertView.findViewById(R.id.btnDelete);
cmdDelete.setBackgroundColor(Color.TRANSPARENT);
final AlertDialog.Builder adb1 = new AlertDialog.Builder(Comm.this);
final AlertDialog.Builder adb2 = new AlertDialog.Builder(Comm.this);
cmdDelete.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
adb1.setTitle("Delete?");
adb1.setMessage("Are you sure delete [" + MyArrList.get(position).get("NOM_PLAT") +"]");
adb1.setNegativeButton("Cancel", null);
adb1.setPositiveButton("Ok", new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String url = "http://192.168.1.7/deleteData.php";
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("sIDCOMMANDES", MyArrList.get(position).get("ID_COMMANDES")));
String resultServer = getJSONUrll(url, params);
String strStatusID = "0";
String strError = "Unknown Status";
try {
JSONObject c = new JSONObject(resultServer);
strStatusID = c.getString("StatusID");
strError = c.getString("Error");
} catch (JSONException e) {
e.printStackTrace();
}
if(strStatusID.equals("0"))
{
adb2.setTitle("Error! ");
adb2.setPositiveButton("Close", null);
adb2.setMessage(strError);
adb2.show();
}
else
{
Toast.makeText(Comm.this, "Delete data successfully.", Toast.LENGTH_SHORT).show();
ShowData(); // reload data again
}
}});
adb1.show();
}
});
然后在您的代码中,您将像<button dojoType="dijit.form.Button" data-dojo-attach-point="myButton">button</button>
一样访问它,但我不确定您使用的是哪个版本的dojo。这将修复任何id问题,因为dojo将自动为其分配唯一的ID。