简体   繁体   English

使小部件成为新小部件的子代

[英]Making widget a child of new widget

Here is the situation. 这是情况。 My company has some widget controls that have been in place for a year or so. 我公司有一些控件已经使用了一年左右。 I am being asked to add a "search function" to the widget. 我被要求向小部件添加“搜索功能”。 Up to this point, the widget is on a page where the field is being passed into it via a cookie. 到目前为止,该小部件位于页面上,其中该字段是通过Cookie传递给它的。 So my question is this, is there a way to create new widget that inside the template it references the old widget and assigns its properties at run time? 所以我的问题是,有没有一种方法可以创建新的小部件,使其在模板中引用旧的小部件并在运行时分配其属性?

Here is some sample 这是一些样品

dojo.provide("company.billing.paymentSearch"); 
dojo.require("dijit._Widget"); 
dojo.require("dijit._Templated"); 
dojo.require("company.test.inquiry"); 

dojo.declare( 
    "company.billing.paymentSearch", 
    [dijit._Widget, dijit._Templated], 
{ 
    token: "", 
    serviceUrl: "", 

    templatePath: dojo.moduleUrl( 
        "company.billing", 
        "templates/paymentSearch.html" 
    ), 

    constructor: function(params, node) { 
        var self = this; 

        function onLoad() { 
            self.inquiryWidget.token = self.token; 
            self.inquiryWidget.serviceUrl = self.serviceUrl; 
            self.inquiryWidget.brandId = ""; 
            self.inquiryWidget.agencyAccountNumber = ""; 
            self.inquiryWidget.billingAccountNumber = ""; 


            self.paymentWidget.token = self.token; 
            self.paymentWidget.serviceUrl = self.serviceUrl 
        } 

        dojo.addOnLoad(onLoad); 
    }, 
    paymentSearch: function() { 
        var self = this; 
        self.inquiryWidget.billingAccountNumber = self.accountNumber; 

    } 
} 
); 

then my template would be 那么我的模板将是

<div>
<div style="float:left; width:20%; border: 1px solid #CCCCCC;">
    <center>
                    Make a Payment 

    </center>
    <br />

        Account Number 

    <br />
    <input style="width:85%" type="text" dojoattachpoint="accountNumber" />
    <br />
    <div class="searchButton">                                

    </div>
</div>
<div style="float:right; width:79%">
    <div id="inquiryWidget" 
        dojoType="company.billing.inquiry" 
        billingAccountNumber="" 
        agencyAccountNumber="" 
        brandId="" 
        waitPanelText="Loading ..." 
        showAccountSummary = "true" 
        showAccountHistory = "false" 
        token="" 
        serviceUrl="">
    </div>  
</div>        

What I would like to do is on the onclick of the search button, add properties to the inquiryWidget and start it. 我想做的是在搜索按钮的onclick上,将属性添加到queryWidget并启动它。 Is something like this possible? 这样的事情可能吗?

You can programatically create the widget like this: 您可以通过编程方式创建小部件,如下所示:

in the template: 在模板中:

<div id="inquiryWidget" dojoAttachPoint="inquiryNode">

in the onLoad function: 在onLoad函数中:

function onLoad() {
    self.inquiryWidget = new company.billing.inquiry({  
        token: self.token, 
        serviceUrl: self.serviceUrl 
    }, self.inquiryNode);
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM