0

我使用 vue 实例,但它没有解析,我认为问题与在Metro.dialog.Create.content中使用双引号有关。

这是包含表格的主页,它可以正常工作。我在主页打开对话框上的 dblclick 表格和此对话框中显示的另一个表格时添加。

var app2= new Vue({
      el: '#appTable',
      data: {
          squads: [                
          ]
      },        
      mounted: function () {
          Metro.init();
          var self = this;
           $.ajax({
               url: '@Url.Action("Find", "Squad")',
               method: 'GET',
               success: function (data) {
                   self.squads = data;
               },                  
           });
      },
      methods:{
        clickList: function (squad) {
            bindSquadToEditTable(squad.ID);
            Metro.dialog.create({
                title: "Team",
                content:
                  '<div class ="row-4-3 rowspan" >'+
                     '<div id="appTableMembers">'+
                       '<table class="table cell-border ">'+
                         '<thead>'+
                            '<tr>'+
                            '<th>Personal Code</th>'+
                             '<th>Name</th>'+
                              '<th>Email</th>'+
                               '</tr>'+
                          '</thead>'+
                       '<tbody>'+
                       "<tr v-for=squad in members :key=squad.PersonalCode >  <td>{{squad.PersonalCode}}</td>  <td>{{squad.FullName}}</td> <td>{{squad.Email}}</td>"+
                        '</tr>'+
                        '</tbody>'+
                  '</table>'+
                 '</div>',
            });
        }
      }
  });

那是我的主页;

        <div id="appTable">
    <table class="table striped">
        <thead>
        <tr>
            <th>Code</th>
            <th>Description</th>
        </tr>
        </thead>
        <tbody>
            <tr v-for="squad in squads" :key="squad.Code" v-on:dblclick="clickList(squad)">
                <td>{{squad.Code}}</td> <td>{{squad.Description}}</td> 
            </tr>
        </tbody>
    </table>
    </div>

这是对话框的绑定数据;

   <script>
         function bindSquadToEditTable(ID){
              app3 = new Vue({
                  el: 'appTableMembers',
                  data: {
                      members:[]
                  },
                  mounted:function(){
                      Metro.init();
                      var self = this;
                      $.ajax({
                          type: "GET",
                          "url": '@Url.Action("FindByID", "Squad")',
                  "data": { id: ID },
                  "dataSrc": "",
                  success: function(data){
                      self.members = data;
                  },
              });
          }
       })
     }
  </script>
4

2 回答 2

0

我改变了我的看法,我将在脚本中实现模态;

<script type="text/template" id="data-input-form-template" >
            <label>Code</label>
            <input type="text" v-model="squad[0].Code"/> 

            <label>Name</label>
            <input type="text" v-model="squad[0].Name" />


            <label>Description</label>
            <textarea style="height:175px" v-model="squad[0].Description"></textarea>

        <div id="appTableMembers">
            <table class="cell-border" >
                <thead>
                    <tr>
                        <th>Personal Code</th>
                        <th>Adı</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="m in squad[0].members">
                        <td>{{m.PersonalCode}}</td>
                        <td>{{m.FullName}}</td>
                    </tr>
                </tbody>
            </table>
         </div>
</script>

这是我的 openDialog 函数;

function openDialog(ID) {       
     var html = $('#data-input-form-template').html();
     $('#data-input-form').html(html);
     app4 =  new Vue({
         el:'#data-input-form',
         data: function(){
             return {
                 squad: [{
                     members: []
                 }]
             }
         },
         mounted:function(){
             Metro.init();
             var self = this;
                 $.ajax({
                     type: "GET",
                     "url": '@Url.Action("FindByID", "Squad")',
                     "data": { id: ID },
                     "dataSrc": "",
                     success: function (data) {
                         self.squad = data;
                     },
                     error: function (error) {
                         alert(error);
                     }
                 });  
         }
     });
    Metro.dialog.open('#demoDialog1');       
}

主页html;

    <div class="dialog" data-role="dialog"  id="demoDialog1"> src="#" />
    <div class="dialog-content" style="height:400px">
        <form id="data-input-form">
        </form>
    </div>
</div>
于 2018-04-16T12:23:12.717 回答
0

我很好奇这将如何工作,所以我进行了快速测试。使用隐藏<div>模式内容工作正常。

HTML

<html>
  <head>
    <link rel="stylesheet" href="https://cdn.metroui.org.ua/v4/css/metro-all.min.css">
  </head>

  <body>
    <div id="app">
      <input type="button" value="modal" @click="showModal" />
      <div style="display: none" ref="modalContent">
        <div>My name is {{name}}</div>
      </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script src="https://cdn.metroui.org.ua/v4/js/metro.min.js"></script>
  </body>

</html>

Javascript

new Vue({
  el: "#app",
  data: {
        name: 'Sample User'
    },
  methods: {
    showModal: function() {
      Metro.dialog.create({
          title: "Modal Title",
          content: this.getModalContent
          });
    },
    getModalContent: function() {
        return this.$refs.modalContent.innerHTML;
    }
  }
});
于 2018-04-11T22:50:18.330 回答