2012-09-08 63 views
0

在Extjs4中使用Ext.apply(obj1,configobject) 讓我們考慮這個樣本例如:Extjs4如何使用Ext在對象內部應用對象

   var obj1 = {}, 
    configobject = { 
    a: 'value', 
    d: 'somevalue', 
    c: { 
     c1 : 10, 
     c2 : 5, 
     c3 : 4 
    } 
}; 
     Ext.apply(obj1, configobject); 
     obj1.c={c2 : 25} 
      document.write(obj1.c.c1 + ', ' + obj1.c.c2 + ', ' + obj1.c.c3); 
            Now the value of obj.c.c1 and obj.c.c3 will show undefined, can anyone tell me the reason 

感謝

回答

1

Ext.apply應能正常工作。這裏是工作示例http://jsfiddle.net/mWaZJ/

+0

我編輯了我的問題..現在看到 – hsnGunda

+2

這是因爲您將'{c2:25}'分配給'obj.c' – maxmalov

+0

您正在重寫自己的值。如果你想'obj'.c.c'存在,調用'Ext.apply(obj1.c,{c2:25})' – Eric