0

First off, this is working just perfectly (doesn't mean there isn't room for improvement so tips are welcomed here as well). My concern though is in a year from now when I need to make an edit, I won't have a clue what any of this means if I leave this as-is so I'm looking for a way to better my code.

var handleActivityEdit = function(id){
    var myContainer = $("#myContainer");
    $.ajax({
        url: "/?go=foo.bar&json",
        type: "post",
        dataType: "JSON",
        data: 'ID=' + id,
        cache: false
    }).then(
        function(response) {
            var html = myContainerTemplate({ 
                viewData: response.data.activityName.DATA
            });
            myContainer.html(html);
        },
        function() {
            console.log("OH SNAP!");
        }
    );       
}

The handlebar template look looks like this (simplified for clarity here) and specifically the {{1}} is what I'd like to know if there is a way to change this variable name (e.g. in SQL, you can do select thisColumnName as ThatColumn).

<ul>
    {{#each viewData}}
        <li>{{1}}</li>
    {{/each}}
</ul>
HPWD
  • 2,232
  • 4
  • 31
  • 61
  • I know I can add comments to the code but just wondering if there was another way. :) – HPWD Sep 06 '18 at 04:32
  • Why don't you return another variable name in your "/?go=foo.bar&json" call ? – Christophe Sep 06 '18 at 06:27
  • I don’t have control over the data being provided. – HPWD Sep 06 '18 at 17:37
  • 1
    Then my advice would be to rename the key 1 in another one in your object before processing the handlebar template. You can find hints on how to do that here https://stackoverflow.com/questions/4647817/javascript-object-rename-key#answer-14592469 – Christophe Sep 07 '18 at 09:14
  • Great information with that post, thanks. – HPWD Sep 07 '18 at 17:00

0 Answers0