2013-12-08 2 views
1

Я работаю с dojo-1.9.1, и я расширяю виджет, где я должен добавить узел <tr> в таблицу в унаследованном шаблонеString. Узел вставлен, но переменные не заменяются. Может ли кто-нибудь взглянуть на источники ниже и указать, что не так в реализации. Кстати, это моя первая попытка создать виджет.dojo 1.9: переменная с заменой на измененный templateString

LVS/виджет/LoginPage.js

define([ 
// Dojo   
    "dojo/_base/declare", 
    "dojo/dom-construct", 
    "dojo/query", 
// Dijit 
    "dijit/_WidgetBase", 
// xwt 
    "xwt/widget/LoginPage", 
    "xwt/widget/CommonUtilities", 
// lvs 
    "dojo/text!./templates/UserRegistration.html" 
], function(
// Dojo 
    declare, 
    domConstruct, 
    query, 
// Dijit  
    _WidgetBase, 
// xwt 
    LoginPage, 
    xwtUtils, 
// lvs 
    UserRegistration 
) { 
    // We declare the namespace of our widget and add the mixins we want to use. 
    return declare("lvs.widget.LoginPage", [ LoginPage, _WidgetBase ], { 

     // userRegistrationLabel: String 
    //  The text used for redirecting to user registration page 
     userRegistrationLabel: "New User? Register here.", 

    // userRegistrationURL: String 
    //  URL for the page to register new user 
     userRegistrationURL: "RegistrationForm.html", 

    // needUserRegistrationLink: Boolean 
    //  Whether the user registration link is visible or hidden 
     needUserRegistrationLink: true, 

     constructor: function(args) { 
     //make the constructor arguments a mixin 
      declare.safeMixin(this, args); 
     }, 

    buildRendering: function() { 
     this.inherited(arguments); 

     var root = this.domNode; 
     var row = domConstruct.toDom(UserRegistration); 

     query('tr[dojoAttachPoint="problemRowAP"]', root).forEach(function(node) { 
       domConstruct.place(row, node, "after");    
     }); 

     this.templateString = this.domNode.innerHTML; 

     // This does not work either  
      //domConstruct.place(UserRegistration, this.problemRowAP, "after"); 
     }, 

     postCreate: function() { 
     this.inherited(arguments); 

      this.set("userRegistrationURL", this.userRegistrationURL); 
      this.set("userRegistrationLabel", this.userRegistrationLabel); 
     }, 

     startup: function() { 
      this.inherited(arguments); 

      if(!this.needUserRegistrationLink){ 
      this._removeUserRegistrationLink(); 
     } 
     }, 

     _showUserRegistrationDlg: function() { 
      xwtUtils.openURL(this.userRegistrationURL, "_new"); 
     }, 

     _removeUserRegistrationLink: function() { 
      dojo.destroy(this.userRegistrationRowAP); 
     }, 

     _setUserRegistrationLabelAttr: function(label) { 
      this._set("userRegistrationLabel", label); 
     }, 

     _setUserRegistrationURLAttr: function(url) { 
      this._set("userRegistrationURL", url); 
     } 
    }); 
}); 

LVS/виджет/шаблоны/UserRegistration.html

<tr data-dojo-attach-point="userRegistrationRowAP"> 
    <td></td> 
    <td class="problem" style="padding-left: 0px; padding-top: 5px;"> 
     <span data-dojo-attach-point="userRegistrationAP" class="problemsLoggingIn" style="margin-left: 8px;"> 
     <a data-dojo-attach-point="userRegistrationAnchor" href="${userRegistrationURL}" target="_top" tabIndex="0" data-dojo-attach-event="ondijitclick:_showUserRegistrationDlg">${userRegistrationURL}</a> 
     </span> 
    </td> 
</tr> 

Код виджета Инстанциация:

var loginPage = new LoginPage({ 
    id: "login_form", 
    // other properties set here... 
    userRegistrationLabel: "New user registration", 
    userRegistrationURL: "RegistrationPage.html", 
    onClickSubmit: function() { 
     alert('The form will be submitted'); 
    } 
}, "login_form"); 

loginPage.set('userRegistrationLabel', 'New User? Register here.'); 
loginPage.set('userRegistrationURL', 'RegistrationPage.html'); 

loginPage.startup(); 

присоединен выходной ниже.

enter image description here

ответ

2

Додзё подстановка переменной происходит в postMixinProperties(), которая проходит до того buildRendering(). Код tr-расширения вызывается из вашего buildRendering(), и это происходит с замененным шаблоном.

Вам необходимо сделать замену шаблона перед основным кодом постмикса, но в этом случае вы не можете сделать это с помощью вызовов domConstruct (потому что на этом этапе они еще не разобраны).

+0

спасибо за понимание. Как вы предлагаете это сделать? –

+1

Вы можете сделать это несколькими способами. Imho самый чистый, если вы наследуете новый виджет с переопределенным шаблоном. Это позволило вам внести дальнейшие изменения в таблицу без манипуляций domConstruct с простым html-кодом. Я уверен, что это не последняя из ваших проблем с шаблонами в додзё, и это не ваша вина. – peterh

+0

Поскольку у меня не хватило времени на прототип, я скопировал шаблон в мое пространство имен и изменил html, чтобы добавить дополнительную строку. Спасибо за предложение. –