简体   繁体   English

尝试使用angularjs将一个输入的值更新为另一个输入的值

[英]Trying to update one input's value to another's using angularjs

I'm fairly new using AngularJS but I've been using for a pet project and I've run in to an issue. 我使用AngularJS还是一个新手,但是我一直在做一个宠物项目,遇到了一个问题。 What I basically want to do is take the text input from this input field: 我基本上想做的是从此输入字段输入文本:

<form id="ci_search_form">
    <p class="input-append"><label>Search:</label> <input type="text" id="query" ng:model="query" autofocus> <button ng:click="clearSearch()" class="btn"><i class="icon-remove"></i></button></p>
</form>

and update this input field's value with that value: 并使用该值更新此输入字段的值:

<div><input type="text" id="ciquery" ng:model="ciquery.Name"></div>

The second input filters some data and I can type in that directly and it works. 第二个输入过滤了一些数据,我可以直接输入该数据并且它可以工作。 However this page will have different sets of data, each with their own search input that I want updated by the master input at the top. 但是,此页面将具有不同的数据集,每组数据都有自己的搜索输入,而我想由顶部的主输入来更新。 I can't set value="" or use jQuery to set the value either, it just appears blank unless I explicitly type in that second input field. 我无法设置value =“”或使用jQuery来设置值,除非我在第二个输入字段中明确输入,否则它只会显示为空白。 Can anyone assist with a solution? 谁能协助解决?

EDIT 编辑

I thought I should include my app and controller code: 我以为我应该包括我的应用程序和控制器代码:

var App = angular.module('TicketAssistApp', []);

App.controller('SearchController', function($scope, $http, $filter){
    $scope.query = '';

    $http.get('static/ci_list.json').success(function(data){
        $scope.ci_list = data;
    });

    $scope.clearSearch = function(){
        $scope.query = '';
    }
});

EDIT 2 编辑2

Made some progress. 取得了一些进展。 Created a function that can be called an update ciquery in $scope: 在$ scope中创建了一个可以称为更新ciquery的函数:

var App = angular.module('TicketAssistApp', []);

App.controller('SearchController', function($scope, $http, $filter){
    $scope.query = '';
    $scope.ciquery = '';

    $http.get('static/ci_list.json').success(function(data){
        $scope.ci_list = data;
    });

    $scope.queryUpdate = function(){
        $scope.ciquery = $scope.query;
    }

    $scope.clearSearch = function(){
        $scope.query = '';
        $scope.queryUpdate();
    }
});

This works great. 这很好。 However, this creates another issue. 但是,这带来了另一个问题。 Before in ciquery I was using ciquery.Name to filter only on the Name attribute. 在ciquery中,以前我使用ciquery.Name仅对Name属性进行过滤。 With this new solution I had to change it to this: 有了这个新的解决方案,我不得不将其更改为:

<div><input type="hidden" id="ciquery" ng:model="ciquery"></div>

This searches all fields in my data which returns unwanted results. 这将搜索我的数据中的所有字段,并返回不需要的结果。 Suggestions? 有什么建议吗?

$scope and ng-model are differents. $ scope和ng-model是不同的。 You should give ng-model's property to ng-click's function. 您应该将ng-model的属性赋予ng-click的函数。 Looks at this -> Ng-model does not update controller value 看这个-> Ng模型不会更新控制器值

To update second input's field (here an example -> http://jsfiddle.net/yEvSL/1/ ) 更新第二个输入的字段(这里是一个示例-> http://jsfiddle.net/yEvSL/1/

<div><input type="text" id="ciquery" ng:model="query"></div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 REACTJS 中的道具将一个组件的输入值显示给另一个组件? - How to display one component's input value to another components using props in REACTJS? AngularJS:使用另一个变量的值命名一个变量 - AngularJS: Name a variable using another's variable value 使用AngularJs指令更新输入值 - Using AngularJs directive to update input value 如何使用vanilla Javascript将一个输入字段的值附加到另一个输入字段的值中? - How to append value of one input field into another input field's value with vanilla Javascript? 在更改angularJs中的另一个选择后,获取选择的值并将其更新为变量 - Get a select's value and update it to a variable after changing another select in angularJs 一个输入文本值更改基于另一个(jquery自动完成)值(经典ASP) - one input text value change base on another one's (jquery autocomplete) value (Classic ASP) 将对象的键绑定到AngularJS中的无线电输入值 - Bind object's key to radio input's value in AngularJS AngularJs-如何使用angular.copy将值从一个输入字段取到另一个字段? - AngularJs - How can i fetch the value from one input field into another field using angular.copy? 尝试从与另一种方法几乎相同的方法中获取 output 值,但该方法不起作用 - Trying to output value from a method that's almost identical to another method but this one is not working 根据另一个输入值更改输入值 - Change input value based on another input's value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM