tags:

views:

191

answers:

2

I don't know much about Dojo but is the following possible:

I assume it has a getter/setter for access to its datastore, is it possible to override this code.

For example:

In the dojo store i have 'Name: @Joe'

is it possible to check the get to:

get()

if name.firstChar = '@' then just
return 'Joe'

and:

set(var)
if name.firstChar = '@' then set to @+var

Is this sort of thing possible? or will i needs a wrapper API?

A: 

Yes, I believe so. I think what you'll want to do is read this here and determine how, if it will work:

The following statement leads me to believe the answer is yes:

... By requiring access to go through store functions, the store can hide the internal structure of the item. This allows the item to remain in a format that is most efficient for representing the datatype for a particular situation. For example, the items could be XML DOM elements and, in that case, the store would access the values using DOM APIs when store.getValue() is called.

As a second example, the item might be a simple JavaScript structure and the store can then access the values through normal JavaScript accessor notation. From the end-users perspective, the access is exactly the same: store.getValue(item, "attribute"). This provides a consistent look and feel to accessing a variety of data types. This also provides efficiency in accessing items by reducing item load times by avoiding conversion to a defined internal format that all stores would have to use. ... Going through store accessor function provides the possibility of lazy-loading in of values as well as lazy reference resolution.

http://www.dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/what-dojo-data/dojo-data-design

I'd love to give you an example but I think it's going to take a lot more investigation.

altCognito
+1  A: 

You can get the best doc from http://docs.dojocampus.org/dojo/data/api/Read

First, for getting the data from a store you have to use

getValue(item, "key")

I believe you can solve the problem the following way. It assumes you are using a ItemFileReadStore, you may use another one, just replace it.

dojo.require("dojo.data.ItemFileReadStore");
dojo.declare("MyStore", dojo.data.ItemFileReadStore, {
    getValue:function(item, key){
        var ret = this.inherited(arguments);
        return ret.charAt(0)=="@" ? ret.substr(1) : ret;
    }
})

And then just use "MyStore" instead of ItemFileReadStore (or whatever store you are using). I just hacked out the code, didn't try it, but it should very well show the solution. Good luck

Wolfram Kriesing