【问题标题】:Dojo DatabindingDojo 数据绑定
【发布时间】:2014-10-22 03:05:33
【问题描述】:

我有一个使用 Dojo UI 构建的 Web 应用程序,当应用程序加载时我调用 parser.parse() 来创建必要的小部件。我现在正尝试从 Ajax 请求到 UI 执行 数据绑定。我一直在看一个示例 here 但是我看到模型是在解析器之前设置的。

我需要能够在函数中设置模型并将其绑定到 UI。 由于我第二次调用 parser.parse() 我收到以下错误:

dojo/parser::parse() error
Error: Tried to register widget with id==xxxx but that id is already registered

还有一种方法我只能解析 bindData 函数并避免此错误吗?

瓶坯绑定功能

var model;

function bindData(data){    
    require([       
        "dojo/Stateful",
        "dojo/parser"   


    ], function( Stateful, parser){     
        model = new Stateful(data); 

parser.parse();    
    });
}

执行查询按钮时调用的函数

if (getSelectedRadioButton('userOption') == 1){

      if (!dijit.byId("employeeNumberId").value){         
          var employeeNumberId = dijit.byId("employeeNumberId");
          dijit.showTooltip(
            employeeNumberId.get('missingMessage'),
            employeeNumberId.domNode
          );
          showNotificationDialog("okResponseNotificationDialog", 'Please Enter A Valid Employee Number Proceed', 'User Options');
          return false;

      }else{
          showNotificationDialog("okResponseNotificationDialog", 'Please Wait While We Retrive Your Data', 'User Options');

          dojo.xhrPost({
              url: getEmployeeData,
              postData: dojo.toJson({
                employeeNumber: EmployeeId
              }),
              handleAs: "text",
              headers: {
                "Content-Type": "application/json",
                "Accept": "application/json"
              },
              sync: true,
              load: function (data) {

                  data = ({First: "John", Last: "Doe", Email: "jdoe@example.com"});

                  bindData(data);                 

              },
              error: function (error) {

                  showNotificationDialog('okResponseNotificationDialog', 'Contact Your HELP DESK  : ' + error, 'Error');
                }

              });         
      }
  }

JSP

<s:textfield required="true" name="Employee.firstname"
  id="surname" placeholder="Your Firstname"
  trim="true"
  data-dojo-type="dijit/form/ValidationTextBox"
  missingMessage="Please Enter Your Firstname!"
  invalidMessage="Invalid Firstname!" title="(a) Firstname:"
  style="width: 20em;" data-dojo-props="value: at(model, 'First.name'), uppercase:true, regExp:'^[`a-zA-Z ]+(([\,\.-][`a-zA-Z ])?[`a-zA-Z ]*)*$'"/>

【问题讨论】:

    标签: javascript jquery parsing dojo


    【解决方案1】:

    是的,你不能调用 parser.parse() 两次。您可能应该使用 EditModelRefController 而不是仅对模型使用 Stateful,然后您应该能够最初使用虚拟数据进行设置,然后在可用时将其替换为真实数据。要查看替换模型的示例,您可以查看此处: https://github.com/dojo/dojox/blob/master/mvc/tests/test_mvc_new-data-replace-simple.html

    【讨论】:

    猜你喜欢
    • 2012-03-09
    • 2013-09-19
    • 1970-01-01
    • 2012-05-29
    • 1970-01-01
    • 1970-01-01
    • 2013-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多