[Users] Modify record in a store

James McManus jmpmcmanus at gmail.com
Fri Oct 2 00:56:40 CEST 2009


After thinking about your suggestions, and looking at more documentation, I
found it works if a define a record first. For example:

        var Record = GeoExt.data.FeatureRecord.create([
          { name : "name", mapping : "name" },
          { name : "type", mapping : "type" }
        ]);

        Store = new GeoExt.data.FeatureStore({
          fields: ['name', 'type'],
        });

        var Data = [
          { name : "stfid", type : "string" },
          { name : "ch_0209_r_tax_val", type : "float" }
        ];

        for (var i = 0; i < Data.length; i++) {
          Store.add(
            new Record({
              name : Data[i].name, type : Data[i].type
            })
          );
        }

        var record = Store.getAt(0);
        record.set("name", "ID");

This changes stfid to ID in the DOM, under store.data.items.0.

Using:

var record = store.getAt(0);
record.set("stfid", "ID");

does not work.

Jim

On Thu, Oct 1, 2009 at 12:41 AM, Eric Lemoine
<eric.lemoine at camptocamp.com>wrote:

> Hi
>
> On Thursday, October 1, 2009, James McManus <jmpmcmanus at gmail.com> wrote:
> > The id is an artifact of my experimentation. I should of left it out.
> > A cleaner version would be:
> >
> >         var Store = new GeoExt.data.FeatureStore({
> >           fields: [
> >              {name: 'stfid', type: 'string'},
> >              {name: 'ch_0209_r_tax_val', type: 'float'}
> >           ]
> >         });
>
> The array passed to the "field" option represents the data schema of
> the store, not the actual data. Use the "data" option to pass actual
> data.
>
> >         var record = Store.getAt(0);
> >         record.set("name","ID");
>
> if you want to change the value of the first record's stfid field you'll do
>
> var record = store.getAt(0);
> record.set("stfid", "ID");
>
> Hope this helps,
>
> >
> > in which I get the error message "record is undefined".  That may mean
> that Store.getAt(0) is not working. Although I have not found an error.
> >
> > I've been looking at Ext JS documentation.  That is where I got the idea
> to use record.set to modify a record. However, the examples I've seen look
> like:
> >
> > var Store = new. Ext.data.Store({
> >     [{name: 'stfid', type: 'string'},
> >      {name: 'ch_0209_r_tax_val']
> > }
> >
> > There is no fields, like I'm using in GeoExt.data.FeatureStore. The API
> for FeatureStore does not list fields as a config option. Is it inherited
> from Ext.data.Store?
> >
> > In any case I'm unsure how to work with it.
> >
> > Thanks
> > Jim
> >
> > On Wed, Sep 30, 2009 at 9:50 PM, Matt Priour <
> mpriour at kestrelcomputer.com <javascript:_e({}, 'cvml', '
> mpriour at kestrelcomputer.com');>> wrote:
> >
> >
> >
> >
> >
> > You've got a whole lot of things going wrong
> > there.
> > You should really look into the ExtJS docs
> > regarding DataStores.
> > http://www.extjs.com/deploy/ext-2.2/docs/?class=Ext.data.JsonStore
> >
> > id is a property of the store, not the field. id
> > refers to the field whose value will be used as the record's id and used
> in
> > functions like getById.
> > the function record.set modifies the value found in
> > the field indicated in the first parameter and changes it to the value
> indicated
> > in the second parameter.
> > Your use of it fails because you don't have a field
> > named "name" .
> > If you did it would change the value in that field
> > in the record to the string "id"
> >
> > Hope that helps at least point you in the right
> > direction to begin accomplishing what you are wanting to do.
> >
> > Matt Priour
> > Kestrel Computer Consulting
> >
> >
> >
> >
> > From: James McManus <javascript:_e({}, 'cvml', 'jmpmcmanus at gmail.com');>
> > Sent: Wednesday, September 30, 2009 6:08 PM
> > To: users at geoext.org <javascript:_e({}, 'cvml', 'users at geoext.org');>
> > Subject: [Users] Modify record in a store
> >
> >
> > Hi - I would like to
> > modify a record in a store, I created using GeoExt.data.FeatureStore. The
> actual
> > store looks like:
> >
> >         var store =
> > new
> > GeoExt.data.FeatureStore({
> > fields:
> > [
> > {id: new Date().getTime(), name: 'stfid', type:
> > 'string'},
> > {id: new Date().getTime(), name: 'ch_0209_r_tax_val', type:
> > 'float'}
> > ]
> >         });
> >
> > I thought I could
> > modify it by doing the following:
> >
> > var record =
> > store.getAt(0);
> > record.set("name", "id");
> >
> > which would change stfid to
> > id. But that did not work. I think it is because I'm not dealing with the
> > presents of "fields".  I've tried a variety of things without
> > success.  Is there a simple way of doing this?
> >
> > Thanks
> > Jim
> >
> >
> >
> >
> > _______________________________________________
> > Users mailing
> > list
> > Users at geoext.org <javascript:_e({}, 'cvml', 'Users at geoext.org');>
> > http://www.geoext.org/cgi-bin/mailman/listinfo/users
> >
> >
> >
>
> --
> Eric Lemoine
>
> Camptocamp France SAS
> Savoie Technolac, BP 352
> 73377 Le Bourget du Lac, Cedex
>
> Tel : 00 33 4 79 44 44 96
> Mail : eric.lemoine at camptocamp.com
> http://www.camptocamp.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20091001/aaf88b12/attachment.htm 


More information about the Users mailing list