在服务器脚本中使用窗口小部件值

时间:2018-01-17 00:22:08

标签: google-app-maker

我可能会彻底过度思考,但在服务器脚本中访问窗口小部件值的最简单方法是什么?

在我的特定情况下,我尝试使用下拉窗口小部件的值作为计算模型查询的过滤器。

function getMonthlyTotalsByResource_() {

  var allRecordsQuery = app.models.Allocations.newQuery();
  allRecordsQuery.filters.Approved._equals = true;
  allRecordsQuery.filters.Resource.Manager.ManagerName._equals = /* How do I make the widget's value available here? */

  var allRecords = allRecordsQuery.run();
...
...

3 个答案:

答案 0 :(得分:1)

在您计算的模型中,服务器脚本中的数据源具有以下内容:

version: '2'
services:
  db:
    image: postgres
    environment:
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=password
    ports:
      - '5432:5432'
  redis:
    image: redis
    ports:
      - '6379:6379'
  celery:
    build:
      context: .
      dockerfile: Dockerfile
    env_file: common.env
    command: celery -A saleor worker --app=saleor.celeryconf:app --loglevel=info
    volumes:
      - .:/app:Z
    links:
      - redis
    depends_on:
      - redis
  search:
    image: elasticsearch:5.4.3
    mem_limit: 512m
    environment:
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ports:
      - '127.0.0.1:9200:9200'
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    env_file: common.env
    depends_on:
      - db
      - redis
      - search
    ports:
      - '8000:8000'
    volumes:
      - .:/app:Z
  makemigrations:
    build: .
    command: python manage.py makemigrations --noinput
    volumes:
      - .:/app:Z
  migration:
    build: .
    command: python manage.py migrate --noinput
    volumes:
      - .:/app:Z

仍然在您的模型数据源中添加一个参数(' String?')并将其命名为ManagerName。

在带有下拉列表的页面上,将窗口小部件的值绑定到@ datasource.properties.ManagerName

在您的服务器脚本中,功能更改为以下内容:

return getMonthlyTotalsByResource_(query);

答案 1 :(得分:0)

最简单的方法是将参数添加到计算模型的数据源中。然后从客户端绑定一些东西(例如绑定到datasource.mycalculatedds.parameters.myparam)。

然后从您计算的数据源传递默认的'query'对象。例如,在您计算的DS中,您可以调用您的函数 getMonthlyTotalsByResource_(查询)。然后你可以设置像

这样的东西
var thismanager = query.parameters.myparam

答案 2 :(得分:0)

// get widget value
function getWidgetValue() {
    var val = app.PAGES.YOUR_PAGE.descendants.WIDGET_NAME.value;
    return val;
}

// execture query 
function getMonthlyTotalsByResource_(widgetValue) {
    var allRecordsQuery = app.models.Allocations.newQuery();
    allRecordsQuery.filters.Approved._equals = true;
    allRecordsQuery.filters.Resource.Manager.ManagerName._equals = widgetValue;
    var allRecords = allRecordsQuery.run();
}
// run 
getMonthlyTotalsByResource_(getWidgetValue);