Nathan 发表于 2024-11-4 09:24:36

创建列表时,行数据重复。

datatable列表,在for循环里使用var line = this.form.get('dt1').addLine();创建列表行时会有重复的行。请问是为何呢?

论坛管理员 发表于 2024-11-4 10:27:07

var line = this.form.get("dt1").addLine();   在哪里调用的,截图看看

Nathan 发表于 2024-11-4 10:46:00

本帖最后由 Nathan 于 2024-11-4 11:51 编辑

/**
               * 在数据表格末尾添加条目。
               * @param {Object} 添加条目的数据。
               * @return {MWF.xApplication.process.Xform.DatatablePC.Line} 添加的数据表格条目
               * @example
               * var line = this.form.get("dt1").addLine();
               */
               
      var unitid = this.session.user.identityList.unit;   //    获取组织id

      var personList1 = this.org.listPersonWithUnit( unitid );   //根据组织id获取人员

      
                var namesList = [];
               
               for (var i = 0; i < personList1.length; i++) {
               
                                 
                              var promise = this.org.listPersonAllAttribute( personList1, true);
                                 
                               promise.then(function(attributeObjectList){
                                       
      
                                 for (var j = 0; j < attributeObjectList.length; j++) {
                                           var nl = attributeObjectList.name;
                                           var attributeList = attributeObjectList.attributeList;
                                          console.log("nl-->"+JSON.stringify(nl));
                                                if(attributeList == "company"){
                                                      console.log("attributeList"+ JSON.stringify(attributeList));
                                                      //1 没有添加上是为何?
                                              namesList.push(personList1.name);
                                             
                                                }
                                                console.log("attributeList2"+ JSON.stringify(attributeList));
                                 }
                                 
               })
                               //2 号问题!!!! 这里 添加重复的行序号    1 122 334455
                                 var line = this.form.get("datatable").addLine();
      
         
      }
               
console.log("211111 - "+JSON.stringify(namesList));//输出为空

for (var i = 0; i < namesList.length; i++) {
//         var line = this.form.get("datatable").addLine();
在里想 把namesList选出的同部门 (企业或事业编)的企业的人找出来,并创建行数据
}
代码里 有俩问题,1 nameList存不上值 2.创建行有重复。请问您我要怎么改呢??

Nathan 发表于 2024-11-4 11:43:27

本帖最后由 Nathan 于 2024-11-4 11:49 编辑

论坛管理员 发表于 2024-11-4 10:27
var line = this.form.get("dt1").addLine();   在哪里调用的,截图看看
var unitid = this.session.user.identityList.unit;   //    获取组织id
var personList1 = this.org.listPersonWithUnit( unitid );   //根据组织id获取人员
console.log("datatable -->" + JSON.stringify(personList1) + "!");
var namesList = [];
//var dataSet = new Set();
for (let i = 0; i < personList1.length; i++) {
    //在这方法里,有true时会主动生成一行行数据,没有时不会主动生成数据行,要手动点“+”号增加行。但人名是有的。
    var promise = this.org.listPersonAllAttribute( personList1,true);
    promise.then(function(attributeObjectList) {
      for (var j = 0; j < attributeObjectList.length; j++) {
            var nl = attributeObjectList.name;
            var attributeList = attributeObjectList.attributeList;
            console.log("nl-->" + JSON.stringify(nl));
            if (attributeList.includes("company")) {
                console.log("attributeList" + JSON.stringify(attributeList));
                namesList.push(personList1.name);
            }
            console.log("attributeList2" + JSON.stringify(attributeList));
      }
      //在这里执行不会触动创建行
      //var line = this.form.get("datatable").addLine();
    });
   //这里创建行时重复的
      var line = this.form.get("datatable").addLine();
}

Nathan 发表于 2024-11-6 09:41:43

论坛管理员 发表于 2024-11-4 10:27
var line = this.form.get("dt1").addLine();   在哪里调用的,截图看看

您好,您知道怎么去掉datatable的操作列“+-”“箭头”么?打印的时候不允许带着。挺着急的,试了很久不知怎么去掉。我今早发帖子了

论坛管理员 发表于 2024-11-6 09:41:47

另一篇帖子里有回复哈
页: [1]
查看完整版本: 创建列表时,行数据重复。