【问题标题】:Editing object with modal jhipster使用模态 jhipster 编辑对象
【发布时间】:2014-11-03 20:05:30
【问题描述】:

我使用 JHipster 来创建我的项目,并且最近进展顺利。但是,我在 main.html 上编辑对象时遇到了问题。当我在路由器指向的posts.html 页面上时,我能够成功地编辑帖子,但是我无法使用main.html 上完全相同的代码来编辑帖子。我可以在我的主页上调用 postController 中的信息,并且可以充分显示。但是,我无法让我的数据出现在模式弹出窗口中。我知道控制器正在接收信息,因为我的 console.log($scope.post) 返回了我要编辑的对象。但是,该信息不会传输到我的模态。任何帮助表示赞赏。

调用编辑的按钮:

//inside postController and an ng-repeat of posts calling update function
<button class="btn btn-primary btn-xs" type="submit" ng-click="update(post.id)" class="btn">
    <span class="glyphicon glyphicon-pencil"></span> Edit
</button>

实际模式代码:

<div ng-controller="postController">
            <textarea class="form-control" rows="3" placeholder="Status update here..." data-toggle="modal" data-target="#savePostModal" ng-click="clear()"></textarea>
            <div class="modal fade" id="savePostModal" tabindex="-1" role="dialog" aria-labelledby="myPostLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <form name="form" role="form" novalidate class="ng-scope ng-invalid ng-invalid-required ng-dirty ng-valid-minlength" ng-submit="create()">

                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true" ng-click="clear()">&times;</button>
                                <h4 class="modal-title" id="myPostLabel">Create or edit a Post</h4>
                            </div>
                            <div class="modal-body">
                                <div class="form-group">
                                    <label>ID</label>
                                    <input type="text" class="form-control" name="id" ng-model="post.id" readonly>
                                </div>

                                <div class="form-group">
                                    <label>Title</label>
                                    <input type="text" class="form-control" name="test" placeholder="Title your post..." ng-model="post.name" ng-minlength=1 required>
                                </div>

                                <div class="form-group">
                                    <label>Author</label>
                                    <input type="text" class="form-control" name="test" placeholder="Temporary Field..." ng-model="post.author" ng-minlength=1 required>
                                </div>

                                <div class="form-group">
                                    <label>Text</label>
                                    <textarea rows="8" placeholder="Status update here..." class="form-control" type="text" name="test" ng-model="post.text" ng-minlength=1 required></textarea>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="clear()">
                                    <span class="glyphicon glyphicon-ban-circle"></span> Cancel
                                </button>
                                <button type="submit" ng-disabled="form.$invalid" class="btn btn-primary">
                                    <span class="glyphicon glyphicon-save"></span> Save
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

更新功能

$scope.update = function (id) {
        $scope.post = Post.get({id: id});
        $('#savePostModal').modal('show');
    };

我知道它成功调用了这个 get 函数,但是 $scope.post 中的数据没有被使用。

【问题讨论】:

  • 还有这个问题...

标签: javascript angularjs twitter-bootstrap angularjs-routing


【解决方案1】:

事实证明,为了使模态框工作,它必须与打印按钮的文本位于相同的控制器 div 中。我很确定这是因为如果 div 不同,控制器上的范围也会不同。另外,不要有第二个同名的模态用于测试,因为它不可避免地会因为功能混淆而失败。

<div id="toBeUpdated" ng-controller="postController">
   <div class="modal fade" id="savePostModal" tabindex="-1" role="dialog" aria-labelledby="myPostLabel" aria-hidden="true">
      <div class="modal-dialog">
         <div class="modal-content">
            <form name="form" role="form" novalidate class="ng-scope ng-invalid ng-invalid-required ng-dirty ng-valid-minlength" ng-submit="createMob()">
               <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true" ng-click="clear()">&times;</button>
                  <h4 class="modal-title" id="myPostLabel">Create or edit a Post</h4>
               </div>
               <div class="modal-body">
                  <div class="form-group">
                     <label>ID</label>
                     <input type="text" class="form-control" name="id" ng-model="post.id" readonly>
                  </div>
                  <div class="form-group">
                     <label>Title</label>
                     <input type="text" class="form-control" name="test" placeholder="Title your post..." ng-model="post.name" ng-minlength=1 required>
                  </div>
                  <div class="form-group">
                     <label>Author</label>
                     <input type="text" class="form-control" name="test" placeholder="Temporary Field..." ng-model="post.author" ng-minlength=1 required>
                  </div>
                  <div class="form-group">
                     <label>Text</label>
                     <textarea rows="8" placeholder="Status update here..." class="form-control" type="text" name="test" ng-model="post.text" ng-minlength=1 required></textarea>
                  </div>
               </div>
               <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="clear()">
                  <span class="glyphicon glyphicon-ban-circle"></span> Cancel
                  </button>
                  <button type="submit" ng-disabled="form.$invalid" class="btn btn-primary">
                  <span class="glyphicon glyphicon-save"></span> Save
                  </button>
               </div>
            </form>
         </div>
      </div>
   </div>
   <li class="animate-repeat" ng-repeat="post in posts.slice().reverse() | checkboxAndFilter:search.$:search.author:search.name:search.id:search.text | limitTo: noPostsOnPage">
      <div class="well ng-scope">
         <div name="desktopPost" class="h4">
            <input type="checkbox" name="checkered"> &emsp;{{post.name}}&emsp;&emsp; <span ng-if="post.summary==1" class="animate-if"><button class="btn btn-xs disabled"><span class="glyphicon glyphicon-star-empty"></span></button></span>
            <a class="pull-right" ng-click="changeid(post.id);alignSearch();">{{post.id}}</a>
         </div>
         <div style="display: none" name="mobilePost" class="h4">
            <div ng-click="postNameAlert(post.name);">
               <div name="ellipse" style="white-space: nowrap; overflow: hidden;text-overflow: ellipsis;-o-text-overflow: ellipsis;">{{post.name}}</div>
            </div>
            <input type="checkbox" name="checkered"> &emsp; 
            <span ng-if="post.summary==1" class="animate-if"><button class="btn btn-xs disabled"><span class="glyphicon glyphicon-star-empty"></span></button></span>
            &emsp;&emsp; 
            <a class="pull-right" style="padding-top:7px" ng-click="changeid(post.id);alignSearch();">{{post.id}}</a>
         </div>
         <p>
         <div ng-bind-html="trustHtml(post.text)" hashtagify term-click="tagTermClick($event)" user-click="tagUserClick($event)"></div>
         </p>
         <br> {{post.author}} on {{post.date_Written}}
         <br>
         <div name="desktopSide">
            <button class="btn btn-primary btn-xs" type="submit" ng-click="update(post.id)" class="btn">
            <span class="glyphicon glyphicon-pencil"></span> Edit
            </button>
            <button class="btn btn-danger btn-xs" type="submit" ng-click="delete(post.id);deleteSummary(post.id);" class="btn btn-danger">
            <span class="glyphicon glyphicon-remove-circle"></span> Delete
            </button>
         </div>
         <div style="display:none;" name="mobileSide">
            <button class="btn btn-primary btn-xs" type="submit" ng-click="updateMob(post.id)" class="btn">
            <span class="glyphicon glyphicon-pencil"></span> Edit
            </button>
            <button class="btn btn-danger btn-xs" type="submit" ng-click="delete(post.id);deleteSummary(post.id);" class="btn btn-danger">
            <span class="glyphicon glyphicon-remove-circle"></span> Delete
            </button>
         </div>
         <div class="animate-repeat" ng-repeat="summarized in filterID(post.id)">
            <div class="animate-repeat" ng-repeat="new_post in getPost(summarized.child)">
               <button class="pull-right btn btn-default btn-xs" ng-click="reversePostState(new_post.id, new_post.name, new_post.author)">
               <span id="{{new_post.author}}" class="glyphicon glyphicon-plus"></span>
               </button>
               <div class="well ng-scope">
                  <h4>
                     {{new_post.name}}
                     <div id="{{new_post.name}}" style="display:inline;"> - {{new_post.author}}</div>
                     &emsp;&emsp; <span ng-if="new_post.summary==1" class="animate-if"><button class="btn btn-xs disabled"><span class="glyphicon glyphicon-star-empty"></span></button></span>
                     <a class="pull-right" ng-click="changeElemOnClick('id_search');changeid(new_post.id);">{{new_post.id}}</a>
                  </h4>
                  <div id="{{new_post.id}}" style="display:none;">
                     {{new_post.text}}
                     <br> {{new_post.author}} 
                     on {{new_post.date_Written}}
                     <br>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </li>
   <center ng-if="checkForPosts()">
      <button class="btn btn-default" ng-click="incrementLimit()">
      <span class="glyphicon glyphicon-arrow-down"></span>Show More Posts
      </button>
   </center>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-26
    • 1970-01-01
    • 2016-07-18
    • 2014-11-27
    • 2017-09-11
    相关资源
    最近更新 更多