【问题标题】:update a record using angularjs使用 angularjs 更新记录
【发布时间】:2016-10-20 06:53:17
【问题描述】:

我正在使用angularjsC# 中创建一个Web 应用程序我的应用程序中有多个记录我想更新thode 记录,我创建了Web 服务和更新所需的js 文件我只是想知道我需要如何在文本框和下拉列表中打印上一个值

<input type="text" ng-model="uvenuename" ng-init="uvenuename='{{updateparam.VenueName}}'" value="{{updateparam.VenueName}}" style="margin-left: 5%;" placeholder="Venue Name" text="" height="30" />

<input type="text" ng-model="uvenueadd" ng-init="uvenueadd='{{updateparam.Venueadd}}'" value="{{updateparam.Venueadd}}" style="margin-left: 5%;" placeholder="Venue Address" text="" height="30" />

我做了类似的事情,但如果我想更改单个文本框 (let see),我只更改了场地名称并更新记录,场地地址显示为 {{updateparam.Venueadd}},而我的下拉列表显示空格

<select ng-model="ulocation">
   <option ng-repeat="k in blocation" value="{{k.jlocation}}">
        {{k.jlocation}}
   </option>
</select>

这是我的下拉菜单,如何克服这些流量?

【问题讨论】:

    标签: javascript c# angularjs


    【解决方案1】:

    不要使用 ng-init 和 value 来尝试维护视图和变量之间的绑定,而应该只使用 ng-model 来使用 AngularJS 的双重绑定。您必须不要在 ng-model 中使用原始数据类型才能使其正常工作。

    <input type="text" ng-model="data.uvenuename" style="margin-left: 5%;" placeholder="Venue Name" text="" height="30" />
    
    <input type="text" ng-model="data.uvenueadd" style="margin-left: 5%;" placeholder="Venue Address" text="" height="30" />
    

    选择元素也是如此

    <select ng-model="data.ulocation">
       <option ng-repeat="k in blocation" value="{{k.jlocation}}">
          {{k.jlocation}}
       </option>
    </select>
    

    在 select 标签中,var data.ulocation 将使用 option 标签中 attr 值中的值进行更新。

    数据变量应该是这样的:

    $scope.data = {
        uvenuename: "",
        uvenueadd: "",
        ulocation: ""
    }
    

    【讨论】:

    • 文本框正在工作,但下拉菜单不起作用仍然出现空白
    • “blocation”变量的值是多少?
    • blocation有多个值
    • 我想是这样,但我想知道它是一个数组、一个对象还是什么。如果您可以发布此 var 的值,它可能对解决您的问题很有用。
    • 选择元素中没有选项的唯一两个可能原因是 blocation var 为空或其中的对象没有属性 jlocation 并且您有空选项。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-05
    • 2017-09-04
    • 1970-01-01
    • 1970-01-01
    • 2013-12-01
    • 2017-03-12
    相关资源
    最近更新 更多