在角度方面,我有一个对象:
$scope.myobj = {
"a":"",
"b":"",
"c":""
}
我希望能够在文本框输入上使用ng-repeat和ng-model,以便在文本框中输入将更新“a”,“b”和“c”。现在我的HTML是:
<div ng-repeat="(keyname, keyvalue) in myobj">
<input ng-model="keyvalue" value="{{keyvalue}}">
</div>
答案 0 :(得分:3)
你可以试试这个,
<div ng-repeat="(keyname, keyvalue) in myobj">
<input ng-model="myobj[keyname]" >
</div>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.myobj = {
"a":"",
"b":"",
"c":""
}
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="(keyname, keyvalue) in myobj">
<input ng-model="myobj[keyname]" >
</div>
OBJECT VALUES : {{myobj}}
</div>
&#13;
答案 1 :(得分:0)
你可能需要改变一下你的obj。制作数组(运行代码段)
# Put a wedge between "prefix" and "date.CSV" part.
# We don't salvage the .csv extension, that drops off here.
# Note the space padding before/after \1, we'll use that shortly.
s/([0-9_]+)\.csv/ \1 /g
# in: "abc1_bbb_yyy_2_8_15.csv"
# out: "abc1_bbb_yyy _2_8_15 "
# (If I knew how to do non-greedy matching in sed we could
# strip the prefix e.g. "abc1_bb_yyy" part here as well,
# but if we try that we end up with just "_15 ", e.g. our
# other month & day get eaten).
# Hence sacrificial space character that our
# next substitution will use to cut the prefix.
# Cut the prefix.
# strip up to, but not including, the first non-space char.
# (I don't think you can do non-greedy matching in sed).
s/^.* ([^ ])/\1/
# in: "abc1_bbb_yyy _2_8_15 "
# out: "_2_8_15 "
# change our underscores to two space chars.
# (turns out we need two intermediate spaces for
# the next substitution to work as a single "global" substitution)
s/_/ /g
# in: "_2_8_15 "
# out: " 2 8 15 "
# At this point all of our month/day/year parts
# have *two* spaces between them.
# Next we do zero-padding if necessary.
s/ ([0-9]) / 0\1 /g
# Important: we're looking for a single space before
# and after any single digit.
# in: " 2 8 15 "
# out: " 02 08 15 "
# input broken out by single chars with "spc"= 1 space char.
# +---+---+---+---+---+---+---+---+---+---+---+
# input: |spc|spc| 2 |spc|spc| 8 |spc|spc| 1 | 5 |spc|
# +---+---+---+---+---+---+---+---+---+---+---+
# \ / \ / no match, not
# \ / \ / a single digit.
# \ / \ /
# match 1 match 2
# / \ / \
# / \ / \
# +---+---+---+---+---+---+---+---+---+---+---+
# result |spc| 0 | 2 |spc| 0 | 8 |spc|spc| 1 | 5 |spc|
# +---+---+---+---+---+---+---+---+---+---+---+
# Without "two spaces" between digits this
# would require 3 separate substitutions...
# doing a single global e.g. s/ ([0-9]) / 0\1 /
# Pretty much done, just strip the spaces.
s/ //g
# in: " 02 08 15 "
# out: "020815"
(function ()
{
var app = angular.module("app", []);
function HomeController()
{
var vm = this;
vm.myobj = [{"name":"a"},{"name":"b"},{"name":"c"}];
}
app.controller("HomeController", [HomeController]);
})();
答案 2 :(得分:0)
使用keyname而不是keyvalue。 也为您的数组键赋予一些价值。 然后尝试使用keyvalue。 它肯定会起作用
Use Custom Server. Base Url: http://localhost