Tìm thấy giải pháp (mặc dù vẫn mở để nghe các ý tưởng khác).
Đầu tiên, bạn có thể gọi hàm load() của cửa hàng với đối tượng cấu hình sẽ được chuyển đến một thao tác. Các tài liệu API cho Ext.data.Operation làm cho nó rõ ràng rằng một trong những tùy chọn cấu hình là một mảng của các đối tượng Lọc, vì vậy bạn có thể làm điều này:
var idFilter = Ext.create('Ext.util.Filter', {
property: 'id',
value: '100,200,300'
});
myStore.load({
filters: [ idFilter ]
});
Điều này dẫn đến một yêu cầu nơi chuỗi truy vấn URL chứa ?filter=[{"property"%3Aid%2C"value"%3A100,200,300}]
(nói cách khác, phiên bản được mã hóa URL là [{ property: 'id', value: '100,200,300'}]
).
Bạn cũng có thể gọi số myStore.filter('id', '100,200,300')
mà không cần gọi số .load()
trước. Giả sử bạn có remoteFilter = true trong cửa hàng của bạn, điều này sẽ làm cho một yêu cầu với cùng một tham số truy vấn được hiển thị agove.
Sidenote: bạn có thể thay đổi từ khóa được sử dụng cho 'bộ lọc' bằng cách định cấu hình tùy chọn cấu hình 'filterParam' cho proxy. Ví dụ, nếu filterParam = q, sau đó các chuỗi truy vấn hiển thị ở trên thay đổi: ?q=[{"property"%3Aid%2C"value"%3A100,200,300}]
Second, bạn có thể kiểm soát "cấu trúc" của bộ lọc trong chuỗi truy vấn. Trong trường hợp của tôi, tôi không muốn một cái gì đó như filter = {JSON}, như được hiển thị ở trên. Tôi muốn có một chuỗi truy vấn mà trông như thế này: ?id=100,200,300
Đối với điều này tôi cần phải mở rộng một proxy và ghi đè lên getParams mặc định() chức năng:
Ext.define('myapp.MyRestProxy', {
extend: 'Ext.data.proxy.Rest',
/**
* Override the default getParams() function inherited from Ext.data.proxy.Server.
*
* Note that the object returned by this function will eventually be used by
* Ext.data.Connection.setOptions() to include these parameters via URL
* querystring (if the request is GET) or via HTTP POST body. In either case,
* the object will be converted into one, big, URL-encoded querystring in
* Ext.data.Connection.setOptions() by a call to Ext.Object.toQueryString.
*
* @param {Ext.data.Operation} operation
* @return {Object}
* where keys are request parameter names mapped to values
*/
getParams: function(operation) {
// First call our parent's getParams() function to get a default array
// of parameters (for more info see http://bit.ly/vq4OOl).
var paramsArr = this.callParent(arguments),
paramName,
length;
// If the operation has filters, we'll customize the params array before
// returning it.
if(operation.filters) {
// Delete whatever filter param the parent getParams() function made
// so that it won't show up in the request querystring.
delete paramsArr[this.filterParam];
// Iterate over array of Ext.util.Filter instances and add each
// filter name/value pair to the array of request params.
for (var i = 0; i < operation.filters.length; i++) {
queryParamName = operation.filters[i].property;
// If one of the query parameter names (from the filter) conflicts
// with an existing parameter name set by the default getParams()
// function, throw an error; this is unacceptable and could cause
// problems that would be hard to debug, otherwise.
if(paramsArr[ queryParamName ]) {
throw new Error('The operation already has a parameter named "'+paramName+'"');
}
paramsArr[ queryParamName ] = operation.filters[i].value;
}
}
return paramsArr;
}
});