从tpl Sencha传递论证 [英] Pass Argument From tpl Sencha

查看:95
本文介绍了从tpl Sencha传递论证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的json如下:

({
"status":"TRUE",
"message":"Words",
"data":[
{
  "name":"paint",
  "author":"snooky",
  "word_id":"1",
  "category":"Business",
  "definitions":[
    {
      "rating":"Green",
      "defintion":"to put color to in something",
      "def_id":"1",
      "example":null,
      "author":"pit",
      "is_favourite":"yesStar"
    },
    {
      "rating":"Red",
      "defintion":"this is a new definition of word paint.",
      "def_id":"42",
      "example":null,
      "author":"bull",
      "is_favourite":"noStar"
    }
  ]
}
]
})

我正在解析此值并显示在tpl中,如下所示:

I am parsing this value and show it in tpl as shown below:

{
    xtype: 'list',
    store: 'words',
    height: 140,
    layout: 'fit',
    scrollable: {  
      direction: 'vertical',
      directionLock: true,
    },
    margin: '0 0 5px 0',
    itemTpl: [          
    '<div>',
    '<tpl for="data">',
    '<ul class="parabox">',
    '<li><h2><b>{name}</b></h2>',
    '<tpl for="definitions">',
    '<ul class="para-box-wrapper">',
    '<li class="{rating}"><div >',
    '<div class="paragraph-def" ><p id = "wordDefinition" >{defintion}</p></div>',
    '<span class="authorBox"><i>Author: {author}</i></span>',
    '<div id="favourite" class="{is_favourite}" ></div>',
    '</div>',
    '</li>',
    '</ul>',
    '</tpl>',
    '</li>',
    '</ul>',
    '</tpl>',
    '</div>',
    ].join(''),
    listeners: {
      itemtap : function(list, index, target, record, event) {
  if (event.target.id=='wordDefinition') {
  alert("Rating clicked!");
   console.log(event.target.id);
  console.dir("Definition--"+record);
    //ratingStar();
  }
  if (event.target.id=='favourite') {
   alert('Favourite clicked!');
   console.log(event.target.id);
   console.dir("Favourite--"+record);
  //addToFavourite();
  }
}
}
}

我的控制台如下:

![console] [1]

![console][1]

如上图所示,我想当用户点击定义即超重足球支持者时,当用户点击相应的tpl时,用户点击相应的tpl时,访问def_id和word_id,当我用户点击星号时,我需要获取word_id。
执行record.data.data [0] .definitions [0] .def_id我可以得到它,但我希望它是动态的,因为稍后可能会有4-5定义。

As shown in above pic i want to access def_id and word_id when user clicks on the respective tpl as shown in below image when user clicks on definition i.e overweight football supporter i need it's word_id and when user clicks on star i need to get word_id. Doing record.data.data[0].definitions[0].def_id i can get it but i want it to be dynamic as there may be 4-5 definition later.

![rate] [2]

![rate][2]

我的商店:

Ext.define('MyApp.store.wordsmenu',{
extend: 'Ext.data.Store', 
config:
{
autoLoad:true,
model: 'MyApp.model.words',    
id:'Contacts',
proxy:
{
    type: 'ajax',
    url: 'json', 
    reader:
    {
            rootProperty:''
    }
}
}
});

我的模型是:

Ext.define('MyApp.model.words', {
extend: 'Ext.data.Model',

config: {
   fields: [
        {name: 'status', mapping: 'status'},
        {name: 'message', mapping: 'message'},
        {name:'data', mapping: 'data'},
        {name: 'definitions', mapping: 'definitions.defintion'},
        {name: 'ratings', mapping: 'definitions.rating'},
    ]
}
});

我可以在tpl中显示json值。现在,我应该跟踪点击具体的
定义,并将其ID发送到服务器但无法获取ID。

I am able show json value in tpl. Now, i should keep track of click on specific definition and star and send its id to server but unable to get id.

为了参考记录,您可以请查看此处
任何帮助!

For reference of record you can check here. Any Help!

推荐答案

似乎 roll_id 您的模型的一个字段,所以你应该可以从你的记录中获取:

It seems that roll_id is a field of your model, so you should be able to get it from your record:

var rollId = record.get('roll_id');
ratingStart(rollId);

这篇关于从tpl Sencha传递论证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆