Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Extjs 为什么是我的组合';s存储区不删除记录_Extjs - Fatal编程技术网

Extjs 为什么是我的组合';s存储区不删除记录

Extjs 为什么是我的组合';s存储区不删除记录,extjs,Extjs,我有一个树面板。树中的每个节点都有一个复选框。当用户选中某个节点时,我将该节点的文本作为选项添加到组合框中。这很有魅力 当用户取消选中某个节点时,我想从组合框中删除相应的选项。有时会移除,有时不会。我已经拔头发好几天了。我做错了什么?谢谢 以下是我的控制器中的init函数: init: function () { this.control({ "#problemsTree": { load: this.selectFirstProblem,

我有一个树面板。树中的每个节点都有一个复选框。当用户选中某个节点时,我将该节点的文本作为选项添加到组合框中。这很有魅力

当用户取消选中某个节点时,我想从组合框中删除相应的选项。有时会移除,有时不会。我已经拔头发好几天了。我做错了什么?谢谢

以下是我的控制器中的init函数:

 init: function () {
     this.control({
         "#problemsTree": {
             load: this.selectFirstProblem,
             select: this.showProblemDetail,
             checkchange: this.handleCheckChange
         },
         "#run-problems-button": { click: this.runSelectedProblems },
         "#stop-problems-button": { click: this.stopSelectedProblems }
     });
 }
以下是同一控制器中的handleCheckChange函数:

toggleLogOption: function(record, isChecked) {
         var logStore = Ext.StoreManager.lookup("logs-store");
         if(isChecked && logStore.find("text", record.data.text) == -1) {
             logStore.add(record)
         } else if(!isChecked) {
             logStore.remove(record)
         }
         logStore.sync();
     },

 handleCheckChange: function(node, isChecked) {
     if(node.isLeaf()) { 
         var record = Ext.create("GiipIq.model.Log", {id: node.data.id, text: node.data.text});
         this.toggleLogOption(record, isChecked);
     } else {
         node.cascadeBy(function(nd) { 
                 nd.set("checked", isChecked); 
                 if(nd.isLeaf()) {
                     var record = Ext.create("GiipIq.model.Log", {id: nd.data.id, text: nd.data.text});
                     this.toggleLogOption(record, isChecked);
                 }
             }, 
             this    
         );
     }
 },
这是我的日志组合:

Ext.define("GiipIq.view.Log", {
         extend: "Ext.window.Window",
         alias: "widget.logwindow",
         titleAlign: "center",
         closable: false,
         maximizable: true,
         draggable: false,
         resizable: false,
         overflowX: "hidden",
         border: false,
         layout: 'fit',
         x: (Ext.getBody().getViewSize().width/2) + 2,
         y: 0,
         width: (Ext.getBody().getViewSize().width/2) - 5,
         height: Ext.getBody().getViewSize().height/2,

         initComponent: function () {
             this.items = [{
                 xtype: "panel",
                 itemId: "logPanel",
                 title: "Live Logs ",
                 tools:[{
                     xtype:"combo",
                     width: 250,
                     emptyText: "Filter logs",
                     id: "logFilter",
                     store: Ext.create("GiipIq.store.Logs"),
                     queryMode: "local",                                                                                                                                                                                                     
                     displayField: "text",
                     valueField: "id"
                 }]  
             }]; 
             this.callParent(arguments);
         }   
     });
这是我的日志存储:

Ext.define("GiipIq.store.Logs", {
         extend: "Ext.data.Store",
         storeId:"logs-store",
         model: "GiipIq.model.Log",

         sorters: [{ property: "text", direction: "ASC" }]                                                                                                                                                                                   
     });
这是我的日志模型:

Ext.define("GiipIq.model.Log", {                                                                                                                                                                                                        
         extend: "Ext.data.Model",
         idProperty: "text",
         fields: [
             { name: "id", type: "string"},
             { name: "text", type: "string" }
         ],  

         proxy: {
             type: "localstorage",
             id: "proxy-key",
             listeners: {
                 exception: function(proxy, response, operation, opts) {
                     if(typeof(operation.error) == "string") {
                         Ext.Msg.alert("Error", "Connection to server interrupted" + operation.error);
                     }   
                 }   
             }   
         }   
     });

即使尝试删除,您也总是创建新记录。逻辑应该依赖于id,它们在树和组合中似乎是相同的,当删除时,您应该尝试在combobyid中找到记录并删除它。仅在添加时创建新记录

我把remove(记录)改为removeAt(索引),一切都像一个符咒。我认为remove(record)函数中有一个bug,因为我的调试消息清楚地显示remove(record)确实得到了执行。谢谢你的帮助。很高兴你把问题解决了。如果有帮助,请接受答案。