且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何绑定一个NG重复从里面动态命名的输入数据

更新时间:2023-11-22 12:01:52

我不知道你为什么用这样复杂的数据结构,但这里是我拿就可以了。

  $ scope.copyHistoryData =功能(部分,输入){
        变种historyId = input.model.split(' - ')[0];
        变种historyVal = section.sectionHistory [section.sectionHistory.length-1] [historyId];
        $ scope.model [input.model] = historyVal;
    };

要填写的所有字段:

  $ scope.copyHistoryData =功能(部分){
      angular.forEach(section.sectionHistory [section.sectionHistory.length-1],功能(historyVal,historyId){
        变种inputModel = historyId + - + section.section_id;
        $ scope.model [inputModel] = historyVal;
      });
    };

http://plnkr.co/edit/OOEmgzKB1pqKjSJMayVF?p=$p$ PVIEW

my goal is to be able to copy data from a table row to another table row.

if the data from 2015 has not changed from 2016 the user needs a quick way of copying the values into the 2016 input fields. the models are dynamically created for these forms. the data you see in this image is assigned to a section. the input models are name 'price_min + section_id', price_max + section_id' , etc... the history model does not have the section_id added to the end of the model names. so there needs to be a mapping function that i need help with. I need to map the history values to the current model convention and update the view with the values.

currently i have a click function that brings in the matched section history. here is a screen shot of what that looks like.

in that same function i have the 2016 object array with the current model naming convention.

i need to copy the history values into the inputArray. how i go about doing this, i dont know? I have complete control on how this works. and in the plunker you will see how i did this. if i need to change something else to make this work then that is ok. javascript, jquery, lodash, linq.js is currently being used in project.

working plunker working plunker

$scope.copyHistoryData = function (section) {
    var selected = Enumerable.From(sectionsHistory).Where("x => x.section_id == '" + section.section_id + "'").ToArray();
    selected = selected[0];
    var inputArry = section.sectionInputs;
};

I'm not sure why you use such complex data structure, but here is my take on it

$scope.copyHistoryData = function (section, input) {
        var historyId=input.model.split('-')[0];
        var historyVal=section.sectionHistory[section.sectionHistory.length-1][historyId];
        $scope.model[input.model]=historyVal;
    };

To fill all fields:

$scope.copyHistoryData = function (section) {
      angular.forEach(section.sectionHistory[section.sectionHistory.length-1], function (historyVal, historyId) {
        var inputModel=historyId+"-"+section.section_id;
        $scope.model[inputModel]=historyVal;
      });
    };

http://plnkr.co/edit/OOEmgzKB1pqKjSJMayVF?p=preview