gpt4 book ai didi

javascript - ng-repeat 因对象数组而失败

转载 作者:行者123 更新时间:2023-12-03 07:50:18 25 4
gpt4 key购买 nike

我不明白为什么,没有什么异常。

我有:

Controller

define([
'underscore',
'json!data/options.json'
], function (_, options) {
"use strict";

var parseValue = function (val, type) {

if (!type || type === "text" || type === "password") {
return val;
}

switch (type) {
case 'checkbox':
return !!val;
case 'number':
return parseInt(val);
default:
throw new Error("Unknow type ", type);
}
};

return [
"$scope",
"OptionsService",
function ($scope, OptionsService) {

$scope.ops = _.map(options, function (op, key) {
op.id = key;
op.value = OptionsService.get(key, op.def);
return op;
});

$scope.update = function (opId) {
var op = _.findWhere($scope.ops, {
id: opId
});

OptionsService.set(opId, parseValue(
op.value,
op.type));
};

console.log("Options", $scope.ops);

}
];

});

模板

<ion-content>

<p>{{ops}}</p>

<div class="list">

<label
ng-repat="op in ops"
class="item item-input item-floating-label">
{{op}}
</label>

</div>

console.log 显示 $scope.ops 是正确的:

Options [Object, Object]

<p>{{ops}}</p>显示正确的 json。

但是Angular编译的结果是:

<div class="scroll">

<p class="ng-binding">[{"desc":"Max notifications","type":"number","def":10,"min":0,"max":null,"id":"notifications.max-notifications","value":10},{"desc":"Auto sync","def":false,"type":"checkbox","id":"remote.auto-sync","value":false}]</p>

<div class="list">

<label ng-repat="op in ops" class="item item-input item-floating-label ng-binding">

</label>

</div>

</div>

我缺少什么吗?

最佳答案

这可能有效:

<label ng-repeat="op in ops" 
class="item item-input item-floating-label ng-binding"
ng-bind="op">
</label>

此外,如果标签没有任何用途,请考虑将标签更改为 span。

关于javascript - ng-repeat 因对象数组而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35023453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com