2019/09/23 工作总结
1.bootstrap的uibModal如何在子控制器和母控制器之间双向传值:
先展示工作中的一个实例:
1 public CreateAnswerKey() { 2 var $ctrl = this; 3 var choosenumberofdistractors = this.$uibModal.open({ 4 backdrop: true, 5 templateUrl: "template/ChooseNumberOfDistractors.html", 6 controller: "ChooseNumberOfDistractorsCtrl", 7 controllerAs: "ctrl", 8 resolve: { 9 numberofDistractors: () => this.numberofDistractors 10 } 11 }); 12 choosenumberofdistractors.result.then(function (numberofDistractors) { 13 $ctrl.numberofDistractors = numberofDistractors; 14 $ctrl.AnswerKeySelectedForm = "Form 1"; 15 $ctrl.QuestionAnswer = new Array(numberofDistractors); 16 $ctrl.FormList = new Array($ctrl.numberOfKeyForm); 17 for (var j = 0; j < $ctrl.numberOfKeyForm; j++) { 18 $ctrl.FormList[j] = "Form " + (j + 1); 19 for (var i = 0; i < $ctrl.numberofQuestions; i++) { 20 $ctrl.QuestionAnswer[i + j * $ctrl.numberofQuestions] = (numberofDistractors == 5) ? { A: false, B: false, C: false, D: false, E: false, F: null, G: null, H: null, I: null, J: null, FormID: $ctrl.FormList[j] } : 21 { A: false, B: false, C: false, D: false, E: false, F: false, G: false, H: false, I: false, J: false, FormID: $ctrl.FormList[j] }; 22 } 23 } 24 }); 25 }
1 export class ChooseNumberOfDistractorsCtrl { 2 static readonly $inject = [ 3 "numberofDistractors", 4 "$http", 5 "routeConfig", 6 "$uibModalInstance", 7 "errorHandler", 8 ]; 9 10 constructor( 11 public numberofDistractors: number, 12 private $http: IHttpService, 13 private routeConfig: RouteConfig, 14 private $uibModalInstance: IModalServiceInstance, 15 private errorHandler: ErrorHandler) { } 16 17 FiveDistractors() { 18 this.numberofDistractors = 5; 19 this.$uibModalInstance.close(this.numberofDistractors); 20 } 21 22 TenDistractors() { 23 this.numberofDistractors = 10; 24 this.$uibModalInstance.close(this.numberofDistractors); 25 } 26 }
1 <div class="col-xs-3" ng-show="ctrl.selectedExam.Id || ctrl.newExamId"> 2 <button type="button" class="btn-default btn" ng-click="ctrl.CreateAnswerKey()" 3 ng-disabled="!ctrl.numberofQuestions || !ctrl.numberOfKeyForm || (ctrl.numberOfKeyForm > 99)">Create AnswerKey</button> 4 </div>
1 <script type="text/ng-template" id="template/ChooseNumberOfDistractors.html"> 2 <div class="modal-header"> 3 <h3 class="modal-title">Choose number of Distractor</h3> 4 </div> 5 <div class="modal-body"> 6 <p>How many distractors do you need for this new answerkey?</p> 7 </div> 8 <div class="modal-footer"> 9 <button class="btn btn-primary" ng-click="ctrl.FiveDistractors()">5: A~E</button> 10 <button class="btn btn-primary" ng-click="ctrl.TenDistractors()">10: A~J</button> 11 <button class="btn btn-default" ng-click="$dismiss()">Cancel</button> 12 </div> 13 </script>
(1)首先通过uibModal参数中的resolve将值从母控制器传进子控制器。
(2)子控制器中操作完毕后,通过this.$uibModalInstance.close()来将小括号内的参数传回母控制器。
(3)在uibModal的result.then中用function()来得到小括号内传回的参数。注意此时仍在子控制器中,如果要调用母控制器的作用域内的参数而使用this的话会和子控制器作用域内的this冲突,因此需要在母控制器中用一个其他名字的变量来指向this,这样就可以在子控制器使用该新变量了。
2.在本地数据库中对表结构进行了修改或者增删了表时,需要更新线上数据库。此时我们在Data.CSharp的Migrations文件夹中新建一个C#文件,将对数据库的修改写入这个文件中即可,下面给出一个新增表的例子:
1 [Migration(56, "CreateTableArchive")] 2 3 public class CreateTableArchive : Migration 4 { 5 public override IEnumerable<IMigrationOperation> Up() => new MigrationBuilder() 6 .When(c => !c.TableExists("archive"), 7 m => 8 { 9 m.CreateTable("archive", c => 10 { 11 c.Define(@"CREATE TABLE `archive` ( 12 `RecNo` int(15) NOT NULL AUTO_INCREMENT, 13 `archivesetdate` date NOT NULL, 14 `timestamp` date NOT NULL, 15 `user` int(15) NOT NULL, 16 PRIMARY KEY (`RecNo`) 17 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;"); 18 }); 19 }) 20 .Build(); 21 }

浙公网安备 33010602011771号