提交 115a3239 编写于 作者: L lang

Improve LargeList#getDataModel

上级 accf20c0
...@@ -88,6 +88,10 @@ define(function (require) { ...@@ -88,6 +88,10 @@ define(function (require) {
optionModelIndices[idx] = modelIdx; optionModelIndices[idx] = modelIdx;
optionModels.push(model); optionModels.push(model);
} }
else {
// Reference to the undefined
optionModelIndices[idx] = -1;
}
// Bar chart, line chart which uses category axis // Bar chart, line chart which uses category axis
// only gives the 'y' value. 'x' value is the indices of cateogry // only gives the 'y' value. 'x' value is the indices of cateogry
if (typeof (value) === 'number') { if (typeof (value) === 'number') {
...@@ -244,14 +248,21 @@ define(function (require) { ...@@ -244,14 +248,21 @@ define(function (require) {
}; };
/** /**
* Get model of one data item * Get model of one data item.
* It will create a temporary model if value on idx is not an option.
*/ */
listProto.getDataModel = function (idx) { listProto.getDataModel = function (idx) {
var storage = this._storage; var storage = this._storage;
var optionModelIndices = storage.$optionModelIndices; var optionModelIndices = storage.$optionModelIndices;
var modelIndex = optionModelIndices && optionModelIndices[idx]; var modelIndex = optionModelIndices && optionModelIndices[idx];
return this._optionModels[modelIndex]; var model = this._optionModels[modelIndex];
if (! model) {
// Create a temporary model if value on idx is not an option.
model = new Model(null, this.seriesModel);
}
return model;
}; };
/** /**
......
...@@ -47,6 +47,7 @@ describe('List', function () { ...@@ -47,6 +47,7 @@ describe('List', function () {
somProp: 'foo' somProp: 'foo'
}]); }]);
expect(list.getDataModel(1).get('somProp')).toEqual('foo'); expect(list.getDataModel(1).get('somProp')).toEqual('foo');
expect(list.getDataModel(0).get('somProp')).toBeNull();
}); });
testCase('Empty data', function (List) { testCase('Empty data', function (List) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册