Changing a class via JS API


#1

I just started experimenting with JS API. I was able to change "Metadata" and "Asset Status" of some assets (pages) successfully.

 

I was wondering if its possible to switch/change class applied to a div using JS API. I tried using setContentOfEditableFileAsset function.

 

I am not sure how to specify the "content":"content of file" parameter of this function ?

 

I am using this code : 

function matrixSetContent() {
js_api.setContentOfEditableFileAsset({
   "assetID":"38963",
   "content":"content of file",
   "dataCallback":function() {
   alert("Class updated successfully")}
}) 
}

Here is the error I am getting, taken from console:

Uncaught Required argument "asset_id" missing 
gscope.Squiz_Matrix_API._options 
gscope.Squiz_Matrix_API.setContentOfEditableFileAsset 
matrixSetContent 
onclick

I am not even sure if setContentOfEditableFileAsset function is the correct function to use for this requirement (changing class)...!

 

Any help is highly appreciated.

 

Thanks


(Nic Hubbard) #2

I think the manuals are wrong about what the argument name is for asset id. It should be asset_id, not assetID.


#3

I think the manuals are wrong about what the argument name is for asset id. It should be asset_id, not assetID.

 

Thanks Nic, you were right. I changed the "assetID" to "asset_id" and now there is no error.

 

but what this code "content":"content of file", is doing ? Is it even correct ?


(Nic Hubbard) #4

 

but what this code "content":"content of file", is doing ? Is it even correct ?

 

Have you tested it yet to see if the file contents get set? I cannot remember if you have to send it as a string or base64, but the manuals make it sound like a string.


#5

 

Have you tested it yet to see if the file contents get set? I cannot remember if you have to send it as a string or base64, but the manuals make it sound like a string.

 

Hi Nic, no nothing seems to have changed in the file ...... Any other ideas or if you can point me to a working example, that would be great.

 

Thanks


(Nic Hubbard) #6

 

Hi Nic, no nothing seems to have changed in the file ...... Any other ideas or if you can point me to a working example, that would be great.

 

Thanks

 

What Matrix version are you on?