[英]How to display one component's input value to another components using props in REACTJS?
[英]Trying to update one input's value to another's using angularjs
我使用AngularJS還是一個新手,但是我一直在做一個寵物項目,遇到了一個問題。 我基本上想做的是從此輸入字段輸入文本:
<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>
並使用該值更新此輸入字段的值:
<div><input type="text" id="ciquery" ng:model="ciquery.Name"></div>
第二個輸入過濾了一些數據,我可以直接輸入該數據並且它可以工作。 但是,此頁面將具有不同的數據集,每組數據都有自己的搜索輸入,而我想由頂部的主輸入來更新。 我無法設置value =“”或使用jQuery來設置值,除非我在第二個輸入字段中明確輸入,否則它只會顯示為空白。 誰能協助解決?
編輯
我以為我應該包括我的應用程序和控制器代碼:
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 = '';
}
});
編輯2
取得了一些進展。 在$ 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();
}
});
這很好。 但是,這帶來了另一個問題。 在ciquery中,以前我使用ciquery.Name僅對Name屬性進行過濾。 有了這個新的解決方案,我不得不將其更改為:
<div><input type="hidden" id="ciquery" ng:model="ciquery"></div>
這將搜索我的數據中的所有字段,並返回不需要的結果。 有什么建議嗎?
$ scope和ng-model是不同的。 您應該將ng-model的屬性賦予ng-click的函數。 看這個-> Ng模型不會更新控制器值
更新第二個輸入的字段(這里是一個示例-> http://jsfiddle.net/yEvSL/1/ )
<div><input type="text" id="ciquery" ng:model="query"></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.