AngularJS绑定-选择指令

AngularJS bind select directive

本文关键字:指令 选择 绑定 AngularJS      更新时间:2023-09-26

我在这里有下拉指令链接

需要一些关于如何绑定我的编辑和保存表单的帮助。

查看/编辑:如何在关键字指令中分配我的supplier.statusID?

<tr ng-repeat="supplier in suppliers">
     <td>{{supplier.Id}}</td>                
     <td>{{supplier.Name}}</td>                
     <td>
        <keywords title="Choose Status" label="" array="myKeyword" opt-value="Id" opt-description="Description"></keywords>
        <br />
     </td>
</tr>

对于添加新记录:如何将关键字指令的ID保存到我的供应商。statusID

<div>Name: <input type="text" />
   <br />
   Status: <keywords title="Choose Status" label="" array="myKeyword" opt-value="Id" opt-description="Description"></keywords><br><button>Save</button>
</div>

您只需要在指令的作用域中创建一个名为supplierId的新属性,并将供应商的ID分配给您声明指令的属性

app.directive('keywords', function(){
    return {
        restrict: 'E',
        scope: {
            array: '=',
            supplierId : '='
        },
        template:   '<label>{{label}}</label>' +
                    '<select ng-model="supplierId" ng-options="a[optValue] as a[optDescription] for a in array">'...

在标记中

<td><keywords title="Choose Status" label="" array="myKeyword" opt-value="Id" 
      supplier-id="supplier.Id" opt-description="Description"></keywords>
                    <br />
                </td>

我用叉子叉了你的小提琴,让它工作

http://jsfiddle.net/XmbHY/

我希望这能有所帮助。