我知道这不是您应该这样做的方式,但我们有一个遗留的 jQuery 应用程序,并且已经讨论过将其移至主干。一个吸引人的成语是这样的:
<script type="text/html" id="mi_form_template">
  the data-item-id is the value we are interested in!!!
 <button id="item" data-item-id='23'>here is item</button>
  </script>
我知道您不应该将这样的信息存储在带有主干的 DOM 中。但希望能够预料到有关此的讨论。
我可以像这样访问 item-id 吗?
ItemsRouter = Backbone.Router.extend({
    routes: {
      "new": "newProduct",
      "": "index"
    },
    newProduct: function() {
      alert('here is newProduct');
      var item_id=$(this).data('item-id'); // <- can we do this???
      new ItemFormView( {model: new Item()});
    },
    ind ...
从初步测试来看,这不起作用 - 看起来对 this 的引用不起作用。这是可能的吗?
提前谢谢