如何保存使用角度JS一个DropDownList的ID? [英] How to Save an id for a dropdownlist using angular js?

查看:112
本文介绍了如何保存使用角度JS一个DropDownList的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Angularjs在我的项目的问题。这里是我的code:

控制器

  // GET:API / CustomerLists / 5
    [responseTyp的(typeof运算(CustomerList))]
    公共IHttpActionResult GetCustomerList(INT ID)
    {        VAR数据=(从卡斯特在db.CustomerLists
            加入call24在db.CallingList4
                在cust.CustID等于call24.CustID            其中,cust.CustID == ID            选择新CustomerVM
            {
                客户ID = cust.CustID,
                客户= cust.Customer,
                Call4ID = call24.Call4ID,
                Wk1WebID = call24.Wk1WebID,
                Wk1OrdID = call24.Wk1OrdID            })。第一();        返回OK(数据);    }  // PUT:API / CustomerLists / 5
    [responseTyp的(typeof运算(无效))]
    公共IHttpActionResult PutCustomerList(CustomerVM VM)
    {        如果(ModelState.IsValid)
        {
            VAR卡斯特= db.CustomerLists.Find(vm.CustID);
            VAR call4 = db.CallingList4.Find(vm.Call4ID);            cust.Customer = vm.Customer;
            cust.ContactName = vm.ContactName;            call4.Wk1OrdID = vm.Wk1OrdID;
            call4.Wk1WebID = vm.Wk1WebID;
            db.CustomerLists.Attach(卡斯特);
            db.Entry(卡斯特).STATE = EntityState.Modified;
            db.CallingList4.Attach(call4);
            db.Entry(call4).STATE = EntityState.Modified;            db.SaveChanges();
        }
        返回状态code(的HTTPStatus code.NoContent);
    }

JS

  VAR EditCtrl =功能($范围,$ routeParams,$位置,数据,$ HTTP){VAR ID = $ routeParams.editId;
$ scope.lis = data.get({ID:ID});$ scope.selectTest = NULL;
$ scope.testTest = [];$ HTTP({
    方法:GET,
    网址:'/ API / OrderStatus /',
    数据:{OrderStatID:1}
})。成功(功能(结果){
    $ scope.testTest =结果;
});
$ scope.selectTest1 = NULL;
$ scope.testTest1 = [];$ HTTP({
    方法:GET,
    网址:'/ API / WebStatus /',
    数据:{WebStatID:1}
})。成功(功能(RESULT1){
    $ scope.testTest1 = RESULT1;
});
$ scope.save =功能(){
    data.update({ID:ID} $ scope.lis,函数(){
        $ location.path('/');
    });
};

模板

 <选择类=表格控NG模型=selectTestNG模型=lis.OrderStatID>
                <选项NG重复=S在TESTTESTVALUE ={{s.OrderStatID}}> {{s.OrderStatus}}< /选项>
            < /选择>

视图模型

 公共类CustomerVM
{
    公众诠释客户ID {搞定;组; }
    公共字符串的客户{搞定;组; }
    公众诠释? {优先获得;组; }
    公共字符串联系人姓名{搞定;组; }
    公共字符串ContactNumber {搞定;组; }
    公众诠释Call4ID {搞定;组; }
    公众诠释? Wk1WebID {搞定;组; }
    公众诠释? Wk1OrdID {搞定;组; }
    公众诠释? OrderStatId {搞定;组; }
    公共字符串OrderStatus {搞定;组; }
}

}

当我尝试更新,在CustomerList细节更新就好了,但CallingList4细节返回null当我选择一个状态,我试图挽救一个ID。如何从另一个表中的ID保存到主表是callingList24?请大家帮忙

更新时间:


  

看这个屏幕截图它是从表中选择,但问题并不想要一个id保存到另一个表。



解决方案

我看到它是一个设计问题,而不是code问题

您需要重新设计你的视图模型,包括像状态和CallingList属性的子类。

然后,使用前pression像{{s.Status.ID}}等所有组成性质在传递值

I have a problem in my project using Angularjs. Here is my code:

Controller

     // GET: api/CustomerLists/5


    [ResponseType(typeof(CustomerList))]
    public IHttpActionResult GetCustomerList(int id)
    {

        var data = (from cust in db.CustomerLists
            join call24 in db.CallingList4
                on cust.CustID equals call24.CustID

            where cust.CustID == id

            select new CustomerVM
            {
                CustID = cust.CustID,
                Customer = cust.Customer,
                Call4ID = call24.Call4ID,
                Wk1WebID = call24.Wk1WebID,
                Wk1OrdID = call24.Wk1OrdID



            }).First();

        return Ok(data);

    }



  // PUT: api/CustomerLists/5
    [ResponseType(typeof(void))]
    public IHttpActionResult PutCustomerList(CustomerVM vm)
    {

        if (ModelState.IsValid)
        {
            var cust = db.CustomerLists.Find(vm.CustID);
            var call4 = db.CallingList4.Find(vm.Call4ID);

            cust.Customer = vm.Customer;
            cust.ContactName = vm.ContactName;

            call4.Wk1OrdID = vm.Wk1OrdID;
            call4.Wk1WebID = vm.Wk1WebID;


            db.CustomerLists.Attach(cust);
            db.Entry(cust).State = EntityState.Modified;
            db.CallingList4.Attach(call4);
            db.Entry(call4).State = EntityState.Modified;

            db.SaveChanges();
        }


        return StatusCode(HttpStatusCode.NoContent);


    }

JS

  var EditCtrl = function ($scope, $routeParams, $location, data, $http) {

var id = $routeParams.editId;
$scope.lis = data.get({ id: id });

$scope.selectTest = null;
$scope.testTest = [];

$http({
    method: 'GET',
    url: '/api/OrderStatus/',
    data: { OrderStatID: 1 }
}).success(function(result) {
    $scope.testTest = result;
});


$scope.selectTest1 = null;
$scope.testTest1 = [];

$http({
    method: 'GET',
    url: '/api/WebStatus/',
    data: { WebStatID: 1 }
}).success(function (result1) {
    $scope.testTest1 = result1;
});


$scope.save = function () {
    data.update({ id: id }, $scope.lis, function () {
        $location.path('/');
    });
};

Template

<select class="form-control" ng-model="selectTest" ng-model="lis.OrderStatID">
                <option ng-repeat="s in testTest" value="{{s.OrderStatID}}">{{s.OrderStatus}}</option>
            </select>

View Model

public class CustomerVM
{
    public int CustID { get; set; }
    public string Customer { get; set; }
    public int? Priority { get; set; }
    public string ContactName { get; set; }
    public string ContactNumber { get; set; }
    public int Call4ID { get; set; }
    public int? Wk1WebID { get; set; }
    public int? Wk1OrdID { get; set; }
    public int? OrderStatId { get; set; }
    public string OrderStatus { get; set; }
}

}

When I try to update, the CustomerList details update just fine, but the CallingList4 details return null when I select a status and I try to save an ID. How do I save the ID from another table to the main table which is callingList24? please help

UPDATED

look at this screen shot it does select from the table, but the problem it does not want to save an id to another table.

解决方案

I see it is a design issue rather than code issue

You need to redesign your ViewModel to include subclasses for properties like Status and CallingList

Then pass the value using expression like {{s.Status.ID}} and so on for all composed properites

这篇关于如何保存使用角度JS一个DropDownList的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆