KnockoutJS订阅可观察

时间:2020-02-25 21:51:01

标签: woocommerce knockout.js subscribe gravityforms

我是KnockoutJS的新手,目前学习条件艰巨。我正在使用Gravity Wiz的Gravity Forms和Nested Forms Addon。我已将嵌套表单链接到使用WooCommerce的产品设置。

我的某些产品是捆绑产品,因此当我在“嵌套表格”中选择这些商品时,我试图将捆绑产品链接的产品添加到“父表格”中,而不是捆绑产品本身。这是Knockout JS进入的地方。我已经订阅了ViewModel,这样我就可以查看是否添加/编辑/删除了条目。

我可以在下面的代码所示的条目中看到捆绑的产品,在此之前,我正在对服务器进行Ajax调用,并且已经获得了链接产品的列表,但是我不知道如何附加/将它们绑定到我的viewModel?任何帮助表示赞赏。

self.init = function() {

    //alert("Its a bundled item");
    get the content of the Nest Form Modal
    var gpnf = window.GPNestedForms_2_1;

    //subscribe to the ViewModel
    gpnf.viewModel.entries.subscribe( function( entries ) {
        // I can see my bundled product here
        console.log( entries );

        self.AppendBundledItem(entries, BundleProdArray);
    } );

}

self.AppendBundledItem = function( entries, bp ) {
    //loop through bp and append to entries then return to ViewModel
}

self.init();

0 个答案:

没有答案