首页 > 其他分享 >odoo owl store

odoo owl store

时间:2023-04-20 10:34:46浏览次数:32  
标签:owl task const text tasks odoo store

https://odoo.github.io/owl/playground/

 

/** @odoo-module **/

const { Component, useState, useRef, mount, onMounted, props, useEnv, reactive } = owl;

function useStore(){
    const env = useEnv();
    return useState(env.store);
}

class TaskList{
    nextId = 1;
    tasks = [];
    addTask(text){
        text = text.trim();
        if(text){
            const task = {
                id: this.nextId++,
                text: text,
                isCompleted: false,
            };
            this.tasks.push(task);
        }
    }
    toggleTask(task){
        task.isCompleted = !task.isCompleted;
    }
    deleteTask(task){
        const index = this.tasks.findIndex((t)=>t.id===task.id);
        this.tasks.splice(index, 1);
    }
}

function createTaskStore(){
    return reactive(new TaskList());
}

class Task extends Component{
    static template = "tasktemplate";
    static props = ["task"];
    setup(){
        this.store = useStore();
    }
}

class Root extends Component {
    static template = "roottemplate";
    static components = { Task };
    setup(){
        const inputRef = useRef("add-input");
        onMounted(()=>inputRef.el.focus());
        this.store = useStore();
    }
    addTask(ev){
        if (ev.keyCode === 13){
            this.store.addTask(ev.target.value);
            ev.target.value = "";
        }
    }
}

const env = {
    store: createTaskStore()
};

mount(Root, document.body,  { templates: TEMPLATES, dev: true, env});

  

 

<template>
  <div t-name="tasktemplate">
    <input type="checkbox" t-att-checked="props.task.isCompleted" />
    <t t-esc="props.task.text" />
    <span t-on-click="()=>store.deleteTask(props.task)"> =>X</span>
  </div>
  
  <div t-name="roottemplate">
    <input placeholder="enter new task" t-on-keyup="addTask" t-ref="add-input" />
    <br />
    <t t-foreach="store.tasks" t-as="task" t-key="task.id">
      <Task task="task" />
    </t>
  </div>
</template>

  

标签:owl,task,const,text,tasks,odoo,store
From: https://www.cnblogs.com/pythonClub/p/17335857.html

相关文章

  • odoo owl playground
    https://odoo.github.io/owl/playground/ /**@odoo-module**/const{Component,useState,useRef,mount,props}=owl;classTaskextendsComponent{statictemplate="tasktemplate";staticprops=["task","toggleSt......
  • odoo 开发入门教程系列-准备一些操作(Action)?
    准备一些操作(Action)?到目前为止,我们主要通过声明字段和视图来构建模块。在任何真实的业务场景中,我们都希望将一些业务逻辑链接到操作按钮。在我们的房地产示例中,我们希望能够:取消或将房产设置为已售出接受或拒绝报价有人可能会说,我们已经可以通过手动更改状态来完成这些事情,但这并......
  • docker compose 安装 odoo(补充)
    1.配置扩展目录odoo配置文件/opt/odoo/config/odoo.conf#内容[options]addons_path=/mnt/extra-addonsdb_host=localhostdb_user=odoodb_name=odoodb_password=odoodocker-composer.yml配置version:'3.1'services:web: image:od......
  • ipa上传,提交AppStore,windows上传ipa
    将ipa提交到AppStore需要Mac电脑操作,现在大部分的程序员都是使用混合开发平台windows系统的电脑,自己装虚拟机过程又繁琐。使用此工具只需要网页上点两下帮你完成这些鸡毛蒜皮事,让你有更多的时间花在改bug上1.打开苹果应用商店:https://appstoreconnect.apple.com/2.登录成功......
  • 《花雕学AI》20:ChatGPT使用之体验评测AI EDU的网页版+桌面端+Android+App store组合
    最近准备出门,要去新疆哈密参加活动,一直在寻找手机上可用的AI移动端。昨天在网上偶然找到了AIEDU(这个不是MSRA创立的人工智能开源社区),其链接是:https://ai.aigcfun.com,今天就尝试做个相关体验与学习的记录。打开首页如下:  引言:人工智能聊天机器人ChatGPT是一种基于GPT-......
  • 卸载 microsoft store下载的软件
    点击“开始菜单”,搜索“应用和功能”搜索并选中要卸载的程序,点击“卸载”......
  • odoo 开发入门教程系列-继承(Inheritance)
    继承(Inheritance)Odoo的一个强大方面是它的模块化。模块专用于业务需求,但模块也可以相互交互。这对于扩展现有模块的功能非常有用。例如,在我们的房地产场景中,我们希望在常规用户视图中直接显示销售人员的财产列表。在介绍特定的Odoo模块继承之前,让我们看看如何更改标准CRUD(创建......
  • vuex store
    一,vuex:状态管理(集中式存储应用的所有组件的状态)vuex是vue的插件store:商店二,vuex有那些属性staste:{}-------------用来放数据的,类似于组件中的datagetters:{}-------------就是一个计算属性[类似于组件中的computed]mutations:{}-----------就是一个存放方法的[类似......
  • Odoo16_月份选择(owl)
    1.js/**@odoo-module**/const{Component}=owl;import{registry}from"@web/core/registry";exportclassFsnMonthextendsComponent{setup(){super.setup();}onChangeValue(ev){this.props.record.upda......
  • odoo中用javascript调用model中定义好的方法
    odoo中如果前端界面要调用后台model中写好的方法,很简单。使用do_action即可,比如要调用改res.users的默认语言后执行的方法 odoo.define('switch_language.SwitchLanguageMenu',function(require){"usestrict";varModel=require('web.Model');varse......