首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >覆盖困难的视图模型

覆盖困难的视图模型
EN

Stack Overflow用户
提问于 2015-08-27 22:46:43
回答 3查看 392关注 0票数 18

我试图使用JS替换输入字段中的一些文本,但视图模型每次都会覆盖我的命令。这是我开始使用的HTML:

代码语言:javascript
复制
<td class="new-variants-table__cell" define="{ editVariantPrice: new Shopify.EditVariantPrice(this) }" context="editVariantPrice" style="height: auto;">
    <input type="hidden" name="product[variants][][price]" id="product_variants__price" value="25.00" bind="price" data-dirty-trigger="true">
    <input class="mock-edit-on-hover tr js-no-dirty js-variant-price variant-table-input--numeric" bind-event-focus="onFocus(this)" bind-event-blur="onBlur(this)" bind-event-input="onInput(this)">
</td>

我运行这个JS:

代码语言:javascript
复制
jQuery('#product_variants__price').siblings().removeAttr('bind-event-focus');
jQuery('#product_variants__price').siblings().removeAttr('bind-event-input');
jQuery('#product_variants__price').siblings().removeAttr('bind-event-blur');
jQuery('#product_variants__price').siblings().focus()
jQuery('#product_variants__price').siblings().val("34.00");
jQuery('#product_variants__price').val("34.00");

剩下的HTML代码如下:

代码语言:javascript
复制
<td class="new-variants-table__cell" define="{ editVariantPrice: new Shopify.EditVariantPrice(this) }" context="editVariantPrice" style="height: auto;">
    <input type="hidden" name="product[variants][][price]" id="product_variants__price" value="34.00" bind="price" data-dirty-trigger="true">
    <input class="mock-edit-on-hover tr js-no-dirty js-variant-price variant-table-input--numeric">
</td>

问题是,每次单击输入字段时,值都会恢复为页面加载时的值。

我还尝试在父td中运行该命令,同时更改我的值,以模拟对变量的编辑,并防止默认没有成功:

代码语言:javascript
复制
jQuery('#product_variants__price').siblings().bind('input', function (e) {
    e.preventDefault();
    return false;
});
jQuery('#product_variants__price').siblings().bind('focus', function (e) {
    e.preventDefault();
    return false;
});
jQuery('#product_variants__price').siblings().focus()
jQuery('#product_variants__price').siblings().val("£34.00");
jQuery('#product_variants__price').val("£34.00");
jQuery('#product_variants__price').siblings().keydown()

父td函数:

代码语言:javascript
复制
new Shopify.EditVariantPrice(jQuery('#product_variants__price').parent())

那么,我如何才能成功地编辑输入中的此值并更新视图模型呢?

您可以通过转到此处来亲自尝试:

https://jebus333.myshopify.com/admin/products/2521183043

登录jebus333@mailinator.com密码shop1

编辑:我试图在页面上找到视图模型,但没有成功。此外,在编辑输入字段中的值时没有网络调用,这让我相信这些值是从页面上的某个位置拉回的。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32252575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档