javascript - 重新加载/提交后,角度应用程序从wordpress中删除输入表单
问题描述
我有一个表格:
<table class="widefat" ng-app="myApp" ng-controller="MyCtrl">
<tr>
<td><label for="name_pokemon"><?php _e( "Name", "cpt" ); ?></label></td>
<td><input id="name_pokemon_val" maxlength="{{a1Max}}" name="name_pokemon" type="text" ng-model="a1" ng-change="update()" value="<?php echo esc_textarea( get_post_meta($post->ID, 'name_pokemon', true) ); ?>" placeholder="<?php esc_attr_e( 'Name', 'cpt' ); ?>"></td>
<td>Length: {{a1.length}} Remaining: {{remainingA}}</td>
</tr></table>
我的脚本:
<script>
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.a1='';
var maxA = 21;
$scope.update = function() {
$scope.remainingA = maxA - ($scope.a1.length);
$scope.a1Max = maxA;
}
$scope.update();}</script>
现在我遇到的问题是,在我提交自定义帖子类型后,它会重置输入数据。
我该如何解决?
感谢您的帮助
解决方案
在这里发现了类似的问题
角度应用程序只显示应用程序的值...我通过使用 wordpress 的值初始化应用程序的 var 来修复它
现在看起来像这样:
$scope.a1='<?php echo esc_textarea( get_post_meta($post->ID, 'name_pokemon', true) ); ?>';
$scope.a2='<?php echo esc_textarea( get_post_meta($post->ID, 'code_card_pokemon', true) ); ?>';
$scope.b1='<?php echo esc_textarea( get_post_meta($post->ID, 'lang_pokemon', true) ); ?>';
$scope.b2='<?php echo esc_textarea( get_post_meta($post->ID, 'code_pokemon', true) ); ?>';
$scope.c1='<?php echo esc_textarea( get_post_meta($post->ID, 'setname_pokemon', true) ); ?>';
初始化范围后,它工作得很好。
我希望我能帮助别人
推荐阅读
- sql - 将 NULL 替换为 0
- mysql - Symfony 5 和 Doctrine,找不到使用 3 个相关实体获取结果的方法
- html - HTML 是否需要在文档末尾换行?
- node.js - 在 fetch 方法中调用 graphql 查询
- java - 消息列表的 RSA 解密速度很慢
- python-sphinx - sphinx:嵌套目录中的嵌套包含
- django - virtualenv中的uwsgi,但django的附加守护进程没有得到venv
- lua - 如何在播放器上放置级联(ESP)?
- c++ - MSBuild - 如何在编译时判断文件是否存在并使用它?
- r - 表格:如何衡量不同日期的维度集的相似性?