2017-07-15 13 views
-1

私の入力はオブジェクトline.productにバインドされますが、typeaheadは製品とサプライヤのペアのリストを返しています。現在のps.product as ps.product.code for ps in getProductSupplierRefList($viewValue)は、予想されるproductを返しません。angularjs bootstrap typehead返す子

enter image description here

<input ng-model="line.product" 
           class=" form-control" 
           typeahead="ps.product as ps.product.code for ps in getProductSupplierRefList($viewValue)" 
           typeahead-loading="isLoading" 
           typeahead-on-select="productSupplierSelected($item, line)" 
           typeahead-template-url="productSupplierRefList.html"/> 

getProductSupplierRefList通話のWEBAPIとProductSupplierRefModelのリストを返す:

製品コードは、テキストコントロールに期待されている
public class ProductSupplierRefModel 
{ 

    public ProductRefModel Product { get; set; } 

    public SupplierRefModel Supplier { get; set; } 

} 

enter image description here

どれ提案plsは?

+0

どこgetProductSupplierRefList機能はありますか? –

答えて

1

typeahead-input-formatterを使用してコードを表示します。 ps.product as ps.product.codeのように見えますか?

<input ng-model="line.product" 
           type="text" 
           class=" form-control" 
           ng-keyup="getProductSupplierRefList($event)" 
           typeahead="ps.product as ps.product.code for ps in filterProductSuppliers" 
           typeahead-loading="isLoading" 
           typeahead-input-formatter="formatProduct($model)" 
           typeahead-wait-ms=500 
           typeahead-on-select="productSupplierSelected($item, line)" 
           typeahead-template-url="productSupplierRefList.html" /> 

フォーマッタがどこにあるか:

$scope.formatProduct=function(model) { 
     return model ? model.code : ''; 
    } 

製品コードは、現在予想通りに表示されます:

enter image description here

0

タイプヘッドでは機能を使用しないでください。また、モデルの特性のラクダのケースにも注意してください。

<input ng-model="line.product" 
          class=" form-control" 
          ng-keyup="getProductSupplierRefList($event)" 
          typeahead="ps.Product as ps.Product.Code for ps in productOptions" 
          typeahead-loading="isLoading" 
          typeahead-on-select="productSupplierSelected($item, line)" 
          typeahead-template-url="productSupplierRefList.html"/> 



$scope.productOptions = []; 
$scope.getProductSupplierRefList = function(evt){ 
     var value = angular.element(evt.target).val(); 
     $http.get('url/' + value).then(funtion(response){ 
      $scope.productOptions = response.data; 
     }) 
} 
//test ps.Product.Code with _tojson(ps.Product.Code) 
$scope._tojson= function(obj){ 
     return angular.toJson(obj); 
} 
+0

モデルの特性のラクダのケースにも注意してください。 –

+0

$ viewValue = ng-changeで未定義を追加しますか? – beewest

+0

申し訳ありませんが、$ viewValueの代わりにline.productを使用してください。 –

関連する問題