Javascript 如何通过shopify中的把手抓住产品手柄的最后一个字?

Javascript 如何通过shopify中的把手抓住产品手柄的最后一个字?,javascript,handlebars.js,shopify,liquid,Javascript,Handlebars.js,Shopify,Liquid,客户希望在其他变体(在本例中为尺寸)旁边显示产品颜色名称(通常为变体),但是,他们在手柄中按颜色组织产品-(例如products/le blazer albert engagee noir)。我刚接触ajaxcart用的把手。我已经正确地打印了变体,但我正在努力获得颜色,这是手柄上的最后一个字。我一辈子都搞不懂! 这就是我目前的情况: <span class="ajaxcart__product-meta"> {{product_url}} <

客户希望在其他变体(在本例中为尺寸)旁边显示产品颜色名称(通常为变体),但是,他们在手柄中按颜色组织产品-(例如products/le blazer albert engagee noir)。我刚接触ajaxcart用的把手。我已经正确地打印了变体,但我正在努力获得颜色,这是手柄上的最后一个字。我一辈子都搞不懂! 这就是我目前的情况:

  <span class="ajaxcart__product-meta">
   
{{product_url}}

</span>    
在DOM中正确打印句柄,例如显示“la chemise victor engagee grise”。 但是我如何只打印“grise”的值呢

谢谢


编辑:明白了!cartItem.handle.split(“-”.pop(),

cartItem.handle.split(“-”.pop(),

如果它总是最后一个单词,前缀是破折号,您可以使用正则表达式:)明白:)cartItem.handle.split(“-”.pop(),
    item = {
        key: cartItem.key,
        line: index + 1, // Shopify uses a 1+ index in the API
        url: cartItem.url,
         product_url: cartItem.handle,
(etc) 
},
      items.push(item);
    });