1

ng-repeathtml和这段代码产生的行为有什么区别:

        <div id="settings-row-{{key}}" class='settings-row' ng-repeat="(key, value) in items">
          <div id='settings-source-{{key}}' class='settings-source settings-column'>{{key}}</div>
          <div class='settings-slider settings-column'>
            <input type="range" ng-model="items[key]" min="0" max="4" />
          </div>
        </div>

这个输入的代码:

       <div id="settings-row-science" class='settings-row'>
          <div id='settings-source-science' class='settings-source settings-column'>science</div>
          <div class='settings-slider settings-column'>
            <input type="range" ng-model="items['science']" min="0" max="4" />
          </div>
        </div>
        <div id="settings-row-english" class='settings-row'>
          <div id='settings-source-english' class='settings-source settings-column'>english</div>
          <div class='settings-slider settings-column'>
            <input type="range" ng-model="items['english']" min="0" max="4" />
          </div>
        </div>
        <div id="settings-row-math" class='settings-row'>
          <div id='settings-source-math' class='settings-source settings-column'>math</div>
          <div class='settings-slider settings-column'>
            <input type="range" ng-model="items['math']" min="0" max="4" />
          </div>
        </div>

我试图让第一个ng-repeat代码与第二个键入的代码具有相同的行为,但由于某种原因,第一个代码的滑块会粘住并且不会平滑滑动。然而,第二个代码的滑块滑动顺畅。我没有考虑的差异是什么?任何建议,将不胜感激。

items是:

    {"science":0,"english":3,"math":4}
4

1 回答 1

1

无论如何,我认为这可能是一些问题,尝试将模型定义为列表:

$scope.items = [{
    "name": "science",
    "value": "0"
}, {
    "name": "english",
    "value": "3"
}, {
    "name": "math",
    "value": "4"
}];

其中 HTML 是:

<div ng-controller="fessCntrl">
    <div id="settings-row-{{item.name}}" class='settings-row' ng-repeat="item in items">
        <div id='settings-source-{{item.name}}' class='settings-source settings-column'>{{item.name}}</div>
        <div class='settings-slider settings-column'>
            <input ng-model="item.value" type="range" min="0" max="4" />
        </div>
    </div> <pre>{{items|json}}</pre>
</div>

演示Fiddle

于 2013-11-16T19:32:26.800 回答