2016-07-13 11 views
-3

私は2つのテーブル:siteipを持っています。角プッシュは関数ではありません

site:SITE_ID、名前

ip:ip_id、SITE_IDは、

ip_adress私は、サイトのip_adressの一覧を表示する必要があります。

HTML

<div class="form-group" style="margin-bottom: 0px;"> 
    <label class="col-sm-6 control-label"> 
     <button style="margin-bottom:5px;" ng-click="addIp($index)"> 
     <span class="glyphicon glyphicon-plus"></span> 
     </button> 
    </label> 
    <div class="col-sm-6"> 
     <ul style="list-style-type: none"> 
      <li ng-repeat="ip in site.ips track by $index"> 
      <div class="input-group" > 
       <input type="text" class="form-control input-sm" name="ip_adress" style="display: inline;" ng-model="ip.ip_adress" required /> 
        <div class="input-group-addon"> 
        <i class="glyphicon glyphicon-remove-circle" ng-click="removeIp(site, ip, $index)"></i> 
        </div> 
       </div> 
      </li> 
     </ul> 
    </div> 
</div> 

はJavaScript

$scope.addIp = function(index){ 
    $scope.sites[index].ips[index].ip_adress.push(""); 
} 

それは、このエラーがスローされます。

$scope.sites[index].ips[index].ip_adress.push is not a function

IPSは、IPオブジェクトの集合であり、そしてip_adressはStringです。 どうすればこの問題を解決できますか?

+0

であれば、それは 'ip_address' –

+0

*でなければなりません$scope.sites[index].ips.push(<here_goes_your_object_with_ip_string>);

* "ip_adress文字列である" - はい、文字列にはメソッド '.push'がありません。あなたはこれが何をすると思いますか? – deceze

+0

あなたは、ip_adressは文字列、pushは文字列の関数ではありません。配列と一緒に使用する必要があります。 – Deep

答えて

-3

あなたは次のように自分の配列にプッシュする必要があります:ipsが配列

+0

あなたのお手伝いをありがとう、私はそれを解決します。 '$ scope.sites [インデックス] .ips.push({ \t \t \t \t \t \tがip_id: ""、 \t \t \t \t \t \t SITE_ID:$ scope.sites [インデックス] .site_id、 \t \t \t \t \t \t ip_adress: ""、 \t \t \t \t}); ' しかし、今、私は保存またはメートル'site。$ update()'を呼び出すと、ipオブジェクトのsiteパラメータはnullになります。どうすればこの問題を解決できますか? –

-4

使用

$scope.addIp = function(index){ 
    $scope.sites[index][ips[index]]['ip_adress'].push(""); 
} 
+0

あなたのお手伝いをありがとう、私はそれを解決します。 '$ scope.sites [index] .ips。プッシュ({ \t \t \t \t \t \tがip_id: ""、 \t \t \t \t \t \t SITE_ID:$ scope.sites [インデックス] .site_id、 \t \t \t \t \t \t ip_adress: ""、 \t \t \t \t}); ' しかし、' site。$ update() 'を呼んで変更を保存したり、変更したりすると、ipオブジェクトのサイトパラメータはn ull。どうすればこの問題を解決できますか? –

関連する問題