感谢这里的一些帮助,我得到了Dojo dgrid的工作;甚至想出了如何将它与我的休息服务中的数据联系起来。dgrid(onDemandGrid)在第一次点击按钮时加载,但第二次点击时出错按钮被点击
现在我添加了一个输入框,一个按钮,所有的逻辑发生在按钮单击。但是,第二次点击按钮时,即使在输入字段中有相同的输入值,我也会得到一个错误。
错误:
类型错误:无法读取性能在StoreMixin.js未定义的 '元素':33
我读到这How To reset the OnDemandGrid,但有必要检查网格是否存在并执行不同的逻辑?我不能每次都“新”一个新的吗?
CODE:
<div data-dojo-type="dijit/layout/ContentPane" data-dojo-props='title:"CustomersGrid"'>
<label for="lastnameStartsWith">Lastname Starts With:</label>
<input id="lastnameStartsWith" type="text" name="lastnameStartsWith" value="Wag"
data-dojo-type="dijit/form/TextBox"
data-dojo-props="trim:true, propercase:true" />
<br />
<br />
<button id="queryStudentsButton" data-dojo-type="dijit/form/Button"
data-dojo-type="dijit/form/Button"
data-dojo-props="iconClass:'dijitIconTask'">
<span>Query</span>
<script type='dojo/on' data-dojo-event='click'>
require([
'dstore/RequestMemory',
'dstore/Memory',
'dgrid/OnDemandGrid'
], function (RequestMemory, Memory, OnDemandGrid) {
var url = '../students/' + dojo.byId('lastnameStartsWith').value;
console.log("query students for dataGrid latsnameStartsWith:" + dojo.byId('lastnameStartsWith').value);
require(['dojo/request'], function(request){
request.get(url,
{headers: {"Content-Type": 'application/json',
"username": securityConfig.username,
"password": securityConfig.password}}
)
.then(function(response){
//console.log("string response=" + response);
var respJSON = JSON.parse(response);
var respDataForDGrid = respJSON.recordset;
console.log("got respJSON back, num rows= " + respDataForDGrid.length);
//================================================
// Create an instance of OnDemandGrid referencing the store
console.log("Debug1");
var grid2 = new OnDemandGrid({
collection: new Memory({ data: respDataForDGrid }),
columns: {
student_id: 'ID',
student_firstname: 'First Name',
student_lastname: 'Last Name',
student_city: 'City',
student_state: 'State',
student_zip: 'Zip'
}
}, 'grid2');
console.log("Debug2");
grid2.startup();
console.log("Debug3");
},
function(error){
console.log("Error=" + error);
//dom.byId('studentFeedback').value += response;
});
});
});
</script>
</button>
<h2>My demoGrid - From JSON RestService (Database)</h2>
<div id='grid2'></div>
</div>
部分 -
我试过此页面上的代码和代码的组合: How To reset the OnDemandGrid
if (grid2Registered){
console.log("reuse existing grid");
grid2Registered.set('collection', memStore);
// refresh: clear the grid and re-queries the store for data.
grid2Registered.refresh();
}
else{...
Doc here(https://github.com/SitePen/dgrid/blob/v0.4.3/doc/components/core-components/OnDemandList-and-OnDemandGrid.md)说:
Clears the grid and re-queries the store for data. If keepScrollPosition is true on either the instance or the options passed to refresh, an attempt will be made to preserve the current scroll position. OnDemandList returns a promise from refresh, which resolves when items in view finish rendering. The promise resolves with the QueryResults that were rendered.
如果您已经创建了网格,那么在您的结构/列保持不变的情况下使用新的商店刷新网格总是可取的(至少这是我所做的)。这样,您可以避免每次查询时创建网格的开销。 –
那么你会如何实现呢?保持一个柜台?或者检查如何检查我的grid2是否先前已定义? – NealWalters
如果您采用模板化方法,即在html中定义小部件,则可以使用data-dojo-attach-point来引用网格。如果采取编程方式,则可以为网格分配一个id(请注意,对于每个dijit,id必须是唯一的),并将其引用为dijit.byId('yourId')。 –