These are chat archives for canjs/canjs

Nov 2017
Nov 16 2017 07:23

Guys, could you please explain to me which way to chose if I want to get element from stache on:event="someFunc(element)". According to the documentation I can use %element or @element, but both methods are deprecated. In browser console I can see "WARN: 31: @element is deprecated. Use scope.element instead." If I use scope.element I getting undefined.

The only one working way: get element from function arguments in vm.

Nov 16 2017 09:19

Does can-connect support encodeURIComponent feature? I have a requirement that, # in URL should be replaced with %23.
Say initial URL is https://localhost:8080/sampleservices/api/v1/sample#name
it should be converted to https://localhost:8080/sampleservices/api/v1/sample%23name
Note: Without using a derived property, I should achieve this

const url = " https://localhost:8080/sampleservices/api/v1";
url obj looks like below:
url: {
getData: "{url}",
getListData: "{url}",
createData: ${url}?id={id},
updateData: ${url}/{id},
destroyData: ${url}/{id}

I'm facing this issue while saving the data.

Approach what I'm trying for is something like below:

  1. ${url}/${({id}).replace('#', '%23')}
  2. tried using encodeURIComponent function in the URL
  3. tried to replace '#' in id with '%23' before save call is triggered but the id in the response is getting converted to %23 from #.

Not sure whether I explained the issue clearly but all I need is I have to modify the URL before it gets triggered.

Kevin Phillips
Nov 16 2017 16:26
@alexey1986 scope.element is what you should use, but if that is not working please file an issue and use %element until that is resolved
Chasen Le Hara
Nov 16 2017 19:19
@pavankmv I’m a little confused about what the id is in your examples… if the base is /api/v1, where does sample#name come from?
FYI if using strings in the url object isn’t working for your API, you can provide functions and completely customize how the requests are made.
Check out the example at the bottom of these docs, where getData is a function that returns a Promise: