PDA

View Full Version : script errors while adding a duplicate record into Store



ruralclimber
14 Aug 2009, 11:06 AM
Hi,

I am trying to add a duplicate record into an existing store. Always get strip errors saying:
"Line 9 Error: 'data' is null or not an object", thrown by ext-all.js

the following are my codes


...
//copy the first record into the last row of the grid

loadDataFromRecords: function(records){
var store = this.grid.getStore();
store.removeAll();

if (records.length > 0) {
store.add(records);
store.add(records[0].copy());
}
store.commitChanges();
}

...



Thanks for the help!

Warren

Animal
14 Aug 2009, 11:12 AM
ext-all-debug.js?

Break on all errors?

ruralclimber
14 Aug 2009, 11:25 AM
it is from ext-all.js, or say, the error was thrown from ext js library code, not my application level code.

However, if I add an unique ID in the copy method, the error disappeared.

the following code works. However, I want the two duplicate records in the store are exactly the same initially, including the ID, although I will change one of the duplicate dynamically based on user actions later on.



loadDataFromRecords: function(records){
var store = this.grid.getStore();
store.removeAll();

if (records.length > 0) {
store.add(records);
store.add(records[0].copy(11111111));
}
store.commitChanges();
}

pdegit
14 Aug 2009, 11:30 AM
Isn't being unique one of the properties of an id?

ruralclimber
14 Aug 2009, 11:37 AM
from ext 2.0 API, yes, if no id is specified for copy method, one unique id should be automatically assigned to the copied record.

basically, what I am going to do is to copy the first record in the store and add it into the store.

after the copying, the first record and the last record in the store should be exactly the same initially, although the last record will be dynamically modified later on based on user actions

Animal
14 Aug 2009, 11:44 AM
USE ext-all-debug.js FFS!

You have been around for over a year now and should know better.

pdegit
14 Aug 2009, 11:49 AM
Why don't you just copy the record and give it an id which you know isn't used by one of the existing records? If setting a unique id solves your problem, why don't you just set a unique id? Is there really such a need for keeping the records absolutely identical?

ruralclimber
14 Aug 2009, 11:55 AM
thx.

yes, it is fine to specify an unique ID for the copy method.

my problem is truly resolved. just reported a minor debug for the copy method, looks the unique ID is required for copy method, rather than optional.

this is quite minor. agree.


thx
Warren