Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在使用ng选项时将选定选项的文本指定给其他模型?_Javascript_Angularjs_Select_Model_Ng Options - Fatal编程技术网

Javascript 如何在使用ng选项时将选定选项的文本指定给其他模型?

Javascript 如何在使用ng选项时将选定选项的文本指定给其他模型?,javascript,angularjs,select,model,ng-options,Javascript,Angularjs,Select,Model,Ng Options,我可以创建一个select标记并将数据放在其中。我可以将该select的选定选项指定给一个模型,但不能将其文本指定给另一个模型 下面是一个例子 html: 请看下面的演示 在选择中,将您的模型更改为cutomer,并在输入中使用customer.id customer.name 函数DemoCtrl$scope{ $scope.content=[{ 姓名:Bireysel, 身份证号码:1 }, { 姓名:Kurumsal, 身份证号码:2 }, { 名称:Bireysel&Kurumsal,

我可以创建一个select标记并将数据放在其中。我可以将该select的选定选项指定给一个模型,但不能将其文本指定给另一个模型

下面是一个例子

html:

请看下面的演示 在选择中,将您的模型更改为cutomer,并在输入中使用customer.id customer.name

函数DemoCtrl$scope{ $scope.content=[{ 姓名:Bireysel, 身份证号码:1 }, { 姓名:Kurumsal, 身份证号码:2 }, { 名称:Bireysel&Kurumsal, 身份证号码:3 }]; } 试试这个:

<select ng-model="customer" ng-options="item.name for item in content">

解决方案: 请检查此项。这将解决您的问题 从下拉列表中选择后,所选对象将存储在customer中。然后,此客户对象包含id和名称

你犯的错误是错误的

此处仅将item.id收集到customerId

若你们想要整个物体,那个就按下面的方法做

    <div ng-app>
     <div ng-controller="DemoCtrl">
        <select ng-model="customer" ng-options="item.name for item in content" ng-change="customerName = item.name">
       </select>
       <br/>
       <input disabled="disabled" type="text" ng-model="customer.id"/>
       <input disabled="disabled" type="text" ng-model="customer.name"/>
     </div>
     </div>

谢谢我的朋友+1;mate我如何从javascript中分配所选选项,我在这里进行了测试,但失败了:谢谢mate+1;
<select ng-model="customer" ng-options="item.name for item in content">
<input disabled="disabled" type="text" ng-model="customer.id"/>
<input disabled="disabled" type="text" ng-model="customer.name"/>
     ng-model="customerId"  ng-options="item.id as item.name for item in content"
    <div ng-app>
     <div ng-controller="DemoCtrl">
        <select ng-model="customer" ng-options="item.name for item in content" ng-change="customerName = item.name">
       </select>
       <br/>
       <input disabled="disabled" type="text" ng-model="customer.id"/>
       <input disabled="disabled" type="text" ng-model="customer.name"/>
     </div>
     </div>